lisp.h: Fix a problem with aliasing and vector headers.
[bpt/emacs.git] / src / data.c
1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2011
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20
21 #include <config.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <setjmp.h>
25 #include "lisp.h"
26 #include "puresize.h"
27 #include "character.h"
28 #include "buffer.h"
29 #include "keyboard.h"
30 #include "frame.h"
31 #include "syssignal.h"
32 #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
33 #include "font.h"
34
35 #ifdef STDC_HEADERS
36 #include <float.h>
37 #endif
38
39 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
40 #ifndef IEEE_FLOATING_POINT
41 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
42 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
43 #define IEEE_FLOATING_POINT 1
44 #else
45 #define IEEE_FLOATING_POINT 0
46 #endif
47 #endif
48
49 #include <math.h>
50
51 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
52 static Lisp_Object Qsubr;
53 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
54 Lisp_Object Qerror, Qquit, Qargs_out_of_range;
55 static Lisp_Object Qwrong_type_argument;
56 Lisp_Object Qvoid_variable, Qvoid_function;
57 static Lisp_Object Qcyclic_function_indirection;
58 static Lisp_Object Qcyclic_variable_indirection;
59 Lisp_Object Qcircular_list;
60 static Lisp_Object Qsetting_constant;
61 Lisp_Object Qinvalid_read_syntax;
62 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
63 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
64 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
65 Lisp_Object Qtext_read_only;
66
67 Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp;
68 static Lisp_Object Qnatnump;
69 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
70 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
71 Lisp_Object Qbuffer_or_string_p;
72 static Lisp_Object Qkeywordp, Qboundp;
73 Lisp_Object Qfboundp;
74 Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
75
76 Lisp_Object Qcdr;
77 static Lisp_Object Qad_advice_info, Qad_activate_internal;
78
79 Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
80 Lisp_Object Qoverflow_error, Qunderflow_error;
81
82 Lisp_Object Qfloatp;
83 Lisp_Object Qnumberp, Qnumber_or_marker_p;
84
85 Lisp_Object Qinteger;
86 static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
87 Lisp_Object Qwindow;
88 static Lisp_Object Qfloat, Qwindow_configuration;
89 static Lisp_Object Qprocess;
90 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
91 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
92 static Lisp_Object Qsubrp, Qmany, Qunevalled;
93 Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
94
95 Lisp_Object Qinteractive_form;
96
97 static void swap_in_symval_forwarding (struct Lisp_Symbol *, struct Lisp_Buffer_Local_Value *);
98
99
100 Lisp_Object
101 wrong_type_argument (register Lisp_Object predicate, register Lisp_Object value)
102 {
103 /* If VALUE is not even a valid Lisp object, we'd want to abort here
104 where we can get a backtrace showing where it came from. We used
105 to try and do that by checking the tagbits, but nowadays all
106 tagbits are potentially valid. */
107 /* if ((unsigned int) XTYPE (value) >= Lisp_Type_Limit)
108 * abort (); */
109
110 xsignal2 (Qwrong_type_argument, predicate, value);
111 }
112
113 void
114 pure_write_error (void)
115 {
116 error ("Attempt to modify read-only object");
117 }
118
119 void
120 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
121 {
122 xsignal2 (Qargs_out_of_range, a1, a2);
123 }
124
125 void
126 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
127 {
128 xsignal3 (Qargs_out_of_range, a1, a2, a3);
129 }
130
131 \f
132 /* Data type predicates */
133
134 DEFUN ("eq", Feq, Seq, 2, 2, 0,
135 doc: /* Return t if the two args are the same Lisp object. */)
136 (Lisp_Object obj1, Lisp_Object obj2)
137 {
138 if (EQ (obj1, obj2))
139 return Qt;
140 return Qnil;
141 }
142
143 DEFUN ("null", Fnull, Snull, 1, 1, 0,
144 doc: /* Return t if OBJECT is nil. */)
145 (Lisp_Object object)
146 {
147 if (NILP (object))
148 return Qt;
149 return Qnil;
150 }
151
152 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
153 doc: /* Return a symbol representing the type of OBJECT.
154 The symbol returned names the object's basic type;
155 for example, (type-of 1) returns `integer'. */)
156 (Lisp_Object object)
157 {
158 switch (XTYPE (object))
159 {
160 case_Lisp_Int:
161 return Qinteger;
162
163 case Lisp_Symbol:
164 return Qsymbol;
165
166 case Lisp_String:
167 return Qstring;
168
169 case Lisp_Cons:
170 return Qcons;
171
172 case Lisp_Misc:
173 switch (XMISCTYPE (object))
174 {
175 case Lisp_Misc_Marker:
176 return Qmarker;
177 case Lisp_Misc_Overlay:
178 return Qoverlay;
179 case Lisp_Misc_Float:
180 return Qfloat;
181 }
182 abort ();
183
184 case Lisp_Vectorlike:
185 if (WINDOW_CONFIGURATIONP (object))
186 return Qwindow_configuration;
187 if (PROCESSP (object))
188 return Qprocess;
189 if (WINDOWP (object))
190 return Qwindow;
191 if (SUBRP (object))
192 return Qsubr;
193 if (COMPILEDP (object))
194 return Qcompiled_function;
195 if (BUFFERP (object))
196 return Qbuffer;
197 if (CHAR_TABLE_P (object))
198 return Qchar_table;
199 if (BOOL_VECTOR_P (object))
200 return Qbool_vector;
201 if (FRAMEP (object))
202 return Qframe;
203 if (HASH_TABLE_P (object))
204 return Qhash_table;
205 if (FONT_SPEC_P (object))
206 return Qfont_spec;
207 if (FONT_ENTITY_P (object))
208 return Qfont_entity;
209 if (FONT_OBJECT_P (object))
210 return Qfont_object;
211 return Qvector;
212
213 case Lisp_Float:
214 return Qfloat;
215
216 default:
217 abort ();
218 }
219 }
220
221 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0,
222 doc: /* Return t if OBJECT is a cons cell. */)
223 (Lisp_Object object)
224 {
225 if (CONSP (object))
226 return Qt;
227 return Qnil;
228 }
229
230 DEFUN ("atom", Fatom, Satom, 1, 1, 0,
231 doc: /* Return t if OBJECT is not a cons cell. This includes nil. */)
232 (Lisp_Object object)
233 {
234 if (CONSP (object))
235 return Qnil;
236 return Qt;
237 }
238
239 DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
240 doc: /* Return t if OBJECT is a list, that is, a cons cell or nil.
241 Otherwise, return nil. */)
242 (Lisp_Object object)
243 {
244 if (CONSP (object) || NILP (object))
245 return Qt;
246 return Qnil;
247 }
248
249 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
250 doc: /* Return t if OBJECT is not a list. Lists include nil. */)
251 (Lisp_Object object)
252 {
253 if (CONSP (object) || NILP (object))
254 return Qnil;
255 return Qt;
256 }
257 \f
258 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
259 doc: /* Return t if OBJECT is a symbol. */)
260 (Lisp_Object object)
261 {
262 if (SYMBOLP (object))
263 return Qt;
264 return Qnil;
265 }
266
267 /* Define this in C to avoid unnecessarily consing up the symbol
268 name. */
269 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0,
270 doc: /* Return t if OBJECT is a keyword.
271 This means that it is a symbol with a print name beginning with `:'
272 interned in the initial obarray. */)
273 (Lisp_Object object)
274 {
275 if (SYMBOLP (object)
276 && SREF (SYMBOL_NAME (object), 0) == ':'
277 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object))
278 return Qt;
279 return Qnil;
280 }
281
282 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
283 doc: /* Return t if OBJECT is a vector. */)
284 (Lisp_Object object)
285 {
286 if (VECTORP (object))
287 return Qt;
288 return Qnil;
289 }
290
291 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
292 doc: /* Return t if OBJECT is a string. */)
293 (Lisp_Object object)
294 {
295 if (STRINGP (object))
296 return Qt;
297 return Qnil;
298 }
299
300 DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
301 1, 1, 0,
302 doc: /* Return t if OBJECT is a multibyte string. */)
303 (Lisp_Object object)
304 {
305 if (STRINGP (object) && STRING_MULTIBYTE (object))
306 return Qt;
307 return Qnil;
308 }
309
310 DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
311 doc: /* Return t if OBJECT is a char-table. */)
312 (Lisp_Object object)
313 {
314 if (CHAR_TABLE_P (object))
315 return Qt;
316 return Qnil;
317 }
318
319 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
320 Svector_or_char_table_p, 1, 1, 0,
321 doc: /* Return t if OBJECT is a char-table or vector. */)
322 (Lisp_Object object)
323 {
324 if (VECTORP (object) || CHAR_TABLE_P (object))
325 return Qt;
326 return Qnil;
327 }
328
329 DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0,
330 doc: /* Return t if OBJECT is a bool-vector. */)
331 (Lisp_Object object)
332 {
333 if (BOOL_VECTOR_P (object))
334 return Qt;
335 return Qnil;
336 }
337
338 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
339 doc: /* Return t if OBJECT is an array (string or vector). */)
340 (Lisp_Object object)
341 {
342 if (ARRAYP (object))
343 return Qt;
344 return Qnil;
345 }
346
347 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
348 doc: /* Return t if OBJECT is a sequence (list or array). */)
349 (register Lisp_Object object)
350 {
351 if (CONSP (object) || NILP (object) || ARRAYP (object))
352 return Qt;
353 return Qnil;
354 }
355
356 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0,
357 doc: /* Return t if OBJECT is an editor buffer. */)
358 (Lisp_Object object)
359 {
360 if (BUFFERP (object))
361 return Qt;
362 return Qnil;
363 }
364
365 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0,
366 doc: /* Return t if OBJECT is a marker (editor pointer). */)
367 (Lisp_Object object)
368 {
369 if (MARKERP (object))
370 return Qt;
371 return Qnil;
372 }
373
374 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0,
375 doc: /* Return t if OBJECT is a built-in function. */)
376 (Lisp_Object object)
377 {
378 if (SUBRP (object))
379 return Qt;
380 return Qnil;
381 }
382
383 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
384 1, 1, 0,
385 doc: /* Return t if OBJECT is a byte-compiled function object. */)
386 (Lisp_Object object)
387 {
388 if (COMPILEDP (object))
389 return Qt;
390 return Qnil;
391 }
392
393 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
394 doc: /* Return t if OBJECT is a character or a string. */)
395 (register Lisp_Object object)
396 {
397 if (CHARACTERP (object) || STRINGP (object))
398 return Qt;
399 return Qnil;
400 }
401 \f
402 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
403 doc: /* Return t if OBJECT is an integer. */)
404 (Lisp_Object object)
405 {
406 if (INTEGERP (object))
407 return Qt;
408 return Qnil;
409 }
410
411 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
412 doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
413 (register Lisp_Object object)
414 {
415 if (MARKERP (object) || INTEGERP (object))
416 return Qt;
417 return Qnil;
418 }
419
420 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
421 doc: /* Return t if OBJECT is a nonnegative integer. */)
422 (Lisp_Object object)
423 {
424 if (NATNUMP (object))
425 return Qt;
426 return Qnil;
427 }
428
429 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
430 doc: /* Return t if OBJECT is a number (floating point or integer). */)
431 (Lisp_Object object)
432 {
433 if (NUMBERP (object))
434 return Qt;
435 else
436 return Qnil;
437 }
438
439 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
440 Snumber_or_marker_p, 1, 1, 0,
441 doc: /* Return t if OBJECT is a number or a marker. */)
442 (Lisp_Object object)
443 {
444 if (NUMBERP (object) || MARKERP (object))
445 return Qt;
446 return Qnil;
447 }
448
449 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
450 doc: /* Return t if OBJECT is a floating point number. */)
451 (Lisp_Object object)
452 {
453 if (FLOATP (object))
454 return Qt;
455 return Qnil;
456 }
457
458 \f
459 /* Extract and set components of lists */
460
461 DEFUN ("car", Fcar, Scar, 1, 1, 0,
462 doc: /* Return the car of LIST. If arg is nil, return nil.
463 Error if arg is not nil and not a cons cell. See also `car-safe'.
464
465 See Info node `(elisp)Cons Cells' for a discussion of related basic
466 Lisp concepts such as car, cdr, cons cell and list. */)
467 (register Lisp_Object list)
468 {
469 return CAR (list);
470 }
471
472 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
473 doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
474 (Lisp_Object object)
475 {
476 return CAR_SAFE (object);
477 }
478
479 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0,
480 doc: /* Return the cdr of LIST. If arg is nil, return nil.
481 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
482
483 See Info node `(elisp)Cons Cells' for a discussion of related basic
484 Lisp concepts such as cdr, car, cons cell and list. */)
485 (register Lisp_Object list)
486 {
487 return CDR (list);
488 }
489
490 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
491 doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
492 (Lisp_Object object)
493 {
494 return CDR_SAFE (object);
495 }
496
497 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
498 doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
499 (register Lisp_Object cell, Lisp_Object newcar)
500 {
501 CHECK_CONS (cell);
502 CHECK_IMPURE (cell);
503 XSETCAR (cell, newcar);
504 return newcar;
505 }
506
507 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
508 doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
509 (register Lisp_Object cell, Lisp_Object newcdr)
510 {
511 CHECK_CONS (cell);
512 CHECK_IMPURE (cell);
513 XSETCDR (cell, newcdr);
514 return newcdr;
515 }
516 \f
517 /* Extract and set components of symbols */
518
519 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0,
520 doc: /* Return t if SYMBOL's value is not void. */)
521 (register Lisp_Object symbol)
522 {
523 Lisp_Object valcontents;
524 struct Lisp_Symbol *sym;
525 CHECK_SYMBOL (symbol);
526 sym = XSYMBOL (symbol);
527
528 start:
529 switch (sym->redirect)
530 {
531 case SYMBOL_PLAINVAL: valcontents = SYMBOL_VAL (sym); break;
532 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
533 case SYMBOL_LOCALIZED:
534 {
535 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
536 if (blv->fwd)
537 /* In set_internal, we un-forward vars when their value is
538 set to Qunbound. */
539 return Qt;
540 else
541 {
542 swap_in_symval_forwarding (sym, blv);
543 valcontents = BLV_VALUE (blv);
544 }
545 break;
546 }
547 case SYMBOL_FORWARDED:
548 /* In set_internal, we un-forward vars when their value is
549 set to Qunbound. */
550 return Qt;
551 default: abort ();
552 }
553
554 return (EQ (valcontents, Qunbound) ? Qnil : Qt);
555 }
556
557 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0,
558 doc: /* Return t if SYMBOL's function definition is not void. */)
559 (register Lisp_Object symbol)
560 {
561 CHECK_SYMBOL (symbol);
562 return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
563 }
564
565 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0,
566 doc: /* Make SYMBOL's value be void.
567 Return SYMBOL. */)
568 (register Lisp_Object symbol)
569 {
570 CHECK_SYMBOL (symbol);
571 if (SYMBOL_CONSTANT_P (symbol))
572 xsignal1 (Qsetting_constant, symbol);
573 Fset (symbol, Qunbound);
574 return symbol;
575 }
576
577 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0,
578 doc: /* Make SYMBOL's function definition be void.
579 Return SYMBOL. */)
580 (register Lisp_Object symbol)
581 {
582 CHECK_SYMBOL (symbol);
583 if (NILP (symbol) || EQ (symbol, Qt))
584 xsignal1 (Qsetting_constant, symbol);
585 XSYMBOL (symbol)->function = Qunbound;
586 return symbol;
587 }
588
589 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
590 doc: /* Return SYMBOL's function definition. Error if that is void. */)
591 (register Lisp_Object symbol)
592 {
593 CHECK_SYMBOL (symbol);
594 if (!EQ (XSYMBOL (symbol)->function, Qunbound))
595 return XSYMBOL (symbol)->function;
596 xsignal1 (Qvoid_function, symbol);
597 }
598
599 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0,
600 doc: /* Return SYMBOL's property list. */)
601 (register Lisp_Object symbol)
602 {
603 CHECK_SYMBOL (symbol);
604 return XSYMBOL (symbol)->plist;
605 }
606
607 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0,
608 doc: /* Return SYMBOL's name, a string. */)
609 (register Lisp_Object symbol)
610 {
611 register Lisp_Object name;
612
613 CHECK_SYMBOL (symbol);
614 name = SYMBOL_NAME (symbol);
615 return name;
616 }
617
618 DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
619 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
620 (register Lisp_Object symbol, Lisp_Object definition)
621 {
622 register Lisp_Object function;
623
624 CHECK_SYMBOL (symbol);
625 if (NILP (symbol) || EQ (symbol, Qt))
626 xsignal1 (Qsetting_constant, symbol);
627
628 function = XSYMBOL (symbol)->function;
629
630 if (!NILP (Vautoload_queue) && !EQ (function, Qunbound))
631 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
632
633 if (CONSP (function) && EQ (XCAR (function), Qautoload))
634 Fput (symbol, Qautoload, XCDR (function));
635
636 XSYMBOL (symbol)->function = definition;
637 /* Handle automatic advice activation */
638 if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
639 {
640 call2 (Qad_activate_internal, symbol, Qnil);
641 definition = XSYMBOL (symbol)->function;
642 }
643 return definition;
644 }
645
646 DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0,
647 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
648 Associates the function with the current load file, if any.
649 The optional third argument DOCSTRING specifies the documentation string
650 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
651 determined by DEFINITION. */)
652 (register Lisp_Object symbol, Lisp_Object definition, Lisp_Object docstring)
653 {
654 CHECK_SYMBOL (symbol);
655 if (CONSP (XSYMBOL (symbol)->function)
656 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
657 LOADHIST_ATTACH (Fcons (Qt, symbol));
658 definition = Ffset (symbol, definition);
659 LOADHIST_ATTACH (Fcons (Qdefun, symbol));
660 if (!NILP (docstring))
661 Fput (symbol, Qfunction_documentation, docstring);
662 return definition;
663 }
664
665 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
666 doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
667 (register Lisp_Object symbol, Lisp_Object newplist)
668 {
669 CHECK_SYMBOL (symbol);
670 XSYMBOL (symbol)->plist = newplist;
671 return newplist;
672 }
673
674 DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
675 doc: /* Return minimum and maximum number of args allowed for SUBR.
676 SUBR must be a built-in function.
677 The returned value is a pair (MIN . MAX). MIN is the minimum number
678 of args. MAX is the maximum number or the symbol `many', for a
679 function with `&rest' args, or `unevalled' for a special form. */)
680 (Lisp_Object subr)
681 {
682 short minargs, maxargs;
683 CHECK_SUBR (subr);
684 minargs = XSUBR (subr)->min_args;
685 maxargs = XSUBR (subr)->max_args;
686 if (maxargs == MANY)
687 return Fcons (make_number (minargs), Qmany);
688 else if (maxargs == UNEVALLED)
689 return Fcons (make_number (minargs), Qunevalled);
690 else
691 return Fcons (make_number (minargs), make_number (maxargs));
692 }
693
694 DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0,
695 doc: /* Return name of subroutine SUBR.
696 SUBR must be a built-in function. */)
697 (Lisp_Object subr)
698 {
699 const char *name;
700 CHECK_SUBR (subr);
701 name = XSUBR (subr)->symbol_name;
702 return make_string (name, strlen (name));
703 }
704
705 DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
706 doc: /* Return the interactive form of CMD or nil if none.
707 If CMD is not a command, the return value is nil.
708 Value, if non-nil, is a list \(interactive SPEC). */)
709 (Lisp_Object cmd)
710 {
711 Lisp_Object fun = indirect_function (cmd); /* Check cycles. */
712
713 if (NILP (fun) || EQ (fun, Qunbound))
714 return Qnil;
715
716 /* Use an `interactive-form' property if present, analogous to the
717 function-documentation property. */
718 fun = cmd;
719 while (SYMBOLP (fun))
720 {
721 Lisp_Object tmp = Fget (fun, Qinteractive_form);
722 if (!NILP (tmp))
723 return tmp;
724 else
725 fun = Fsymbol_function (fun);
726 }
727
728 if (SUBRP (fun))
729 {
730 const char *spec = XSUBR (fun)->intspec;
731 if (spec)
732 return list2 (Qinteractive,
733 (*spec != '(') ? build_string (spec) :
734 Fcar (Fread_from_string (build_string (spec), Qnil, Qnil)));
735 }
736 else if (COMPILEDP (fun))
737 {
738 if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
739 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
740 }
741 else if (CONSP (fun))
742 {
743 Lisp_Object funcar = XCAR (fun);
744 if (EQ (funcar, Qclosure))
745 return Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun))));
746 else if (EQ (funcar, Qlambda))
747 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
748 else if (EQ (funcar, Qautoload))
749 {
750 struct gcpro gcpro1;
751 GCPRO1 (cmd);
752 do_autoload (fun, cmd);
753 UNGCPRO;
754 return Finteractive_form (cmd);
755 }
756 }
757 return Qnil;
758 }
759
760 \f
761 /***********************************************************************
762 Getting and Setting Values of Symbols
763 ***********************************************************************/
764
765 /* Return the symbol holding SYMBOL's value. Signal
766 `cyclic-variable-indirection' if SYMBOL's chain of variable
767 indirections contains a loop. */
768
769 struct Lisp_Symbol *
770 indirect_variable (struct Lisp_Symbol *symbol)
771 {
772 struct Lisp_Symbol *tortoise, *hare;
773
774 hare = tortoise = symbol;
775
776 while (hare->redirect == SYMBOL_VARALIAS)
777 {
778 hare = SYMBOL_ALIAS (hare);
779 if (hare->redirect != SYMBOL_VARALIAS)
780 break;
781
782 hare = SYMBOL_ALIAS (hare);
783 tortoise = SYMBOL_ALIAS (tortoise);
784
785 if (hare == tortoise)
786 {
787 Lisp_Object tem;
788 XSETSYMBOL (tem, symbol);
789 xsignal1 (Qcyclic_variable_indirection, tem);
790 }
791 }
792
793 return hare;
794 }
795
796
797 DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0,
798 doc: /* Return the variable at the end of OBJECT's variable chain.
799 If OBJECT is a symbol, follow all variable indirections and return the final
800 variable. If OBJECT is not a symbol, just return it.
801 Signal a cyclic-variable-indirection error if there is a loop in the
802 variable chain of symbols. */)
803 (Lisp_Object object)
804 {
805 if (SYMBOLP (object))
806 {
807 struct Lisp_Symbol *sym = indirect_variable (XSYMBOL (object));
808 XSETSYMBOL (object, sym);
809 }
810 return object;
811 }
812
813
814 /* Given the raw contents of a symbol value cell,
815 return the Lisp value of the symbol.
816 This does not handle buffer-local variables; use
817 swap_in_symval_forwarding for that. */
818
819 Lisp_Object
820 do_symval_forwarding (register union Lisp_Fwd *valcontents)
821 {
822 register Lisp_Object val;
823 switch (XFWDTYPE (valcontents))
824 {
825 case Lisp_Fwd_Int:
826 XSETINT (val, *XINTFWD (valcontents)->intvar);
827 return val;
828
829 case Lisp_Fwd_Bool:
830 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
831
832 case Lisp_Fwd_Obj:
833 return *XOBJFWD (valcontents)->objvar;
834
835 case Lisp_Fwd_Buffer_Obj:
836 return PER_BUFFER_VALUE (current_buffer,
837 XBUFFER_OBJFWD (valcontents)->offset);
838
839 case Lisp_Fwd_Kboard_Obj:
840 /* We used to simply use current_kboard here, but from Lisp
841 code, it's value is often unexpected. It seems nicer to
842 allow constructions like this to work as intuitively expected:
843
844 (with-selected-frame frame
845 (define-key local-function-map "\eOP" [f1]))
846
847 On the other hand, this affects the semantics of
848 last-command and real-last-command, and people may rely on
849 that. I took a quick look at the Lisp codebase, and I
850 don't think anything will break. --lorentey */
851 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
852 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
853 default: abort ();
854 }
855 }
856
857 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
858 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
859 buffer-independent contents of the value cell: forwarded just one
860 step past the buffer-localness.
861
862 BUF non-zero means set the value in buffer BUF instead of the
863 current buffer. This only plays a role for per-buffer variables. */
864
865 static void
866 store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newval, struct buffer *buf)
867 {
868 switch (XFWDTYPE (valcontents))
869 {
870 case Lisp_Fwd_Int:
871 CHECK_NUMBER (newval);
872 *XINTFWD (valcontents)->intvar = XINT (newval);
873 break;
874
875 case Lisp_Fwd_Bool:
876 *XBOOLFWD (valcontents)->boolvar = !NILP (newval);
877 break;
878
879 case Lisp_Fwd_Obj:
880 *XOBJFWD (valcontents)->objvar = newval;
881
882 /* If this variable is a default for something stored
883 in the buffer itself, such as default-fill-column,
884 find the buffers that don't have local values for it
885 and update them. */
886 if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
887 && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
888 {
889 int offset = ((char *) XOBJFWD (valcontents)->objvar
890 - (char *) &buffer_defaults);
891 int idx = PER_BUFFER_IDX (offset);
892
893 Lisp_Object tail;
894
895 if (idx <= 0)
896 break;
897
898 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
899 {
900 Lisp_Object lbuf;
901 struct buffer *b;
902
903 lbuf = Fcdr (XCAR (tail));
904 if (!BUFFERP (lbuf)) continue;
905 b = XBUFFER (lbuf);
906
907 if (! PER_BUFFER_VALUE_P (b, idx))
908 PER_BUFFER_VALUE (b, offset) = newval;
909 }
910 }
911 break;
912
913 case Lisp_Fwd_Buffer_Obj:
914 {
915 int offset = XBUFFER_OBJFWD (valcontents)->offset;
916 Lisp_Object type = XBUFFER_OBJFWD (valcontents)->slottype;
917
918 if (!(NILP (type) || NILP (newval)
919 || (XINT (type) == LISP_INT_TAG
920 ? INTEGERP (newval)
921 : XTYPE (newval) == XINT (type))))
922 buffer_slot_type_mismatch (newval, XINT (type));
923
924 if (buf == NULL)
925 buf = current_buffer;
926 PER_BUFFER_VALUE (buf, offset) = newval;
927 }
928 break;
929
930 case Lisp_Fwd_Kboard_Obj:
931 {
932 char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ());
933 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
934 *(Lisp_Object *) p = newval;
935 }
936 break;
937
938 default:
939 abort (); /* goto def; */
940 }
941 }
942
943 /* Set up SYMBOL to refer to its global binding.
944 This makes it safe to alter the status of other bindings. */
945
946 void
947 swap_in_global_binding (struct Lisp_Symbol *symbol)
948 {
949 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (symbol);
950
951 /* Unload the previously loaded binding. */
952 if (blv->fwd)
953 SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
954
955 /* Select the global binding in the symbol. */
956 blv->valcell = blv->defcell;
957 if (blv->fwd)
958 store_symval_forwarding (blv->fwd, XCDR (blv->defcell), NULL);
959
960 /* Indicate that the global binding is set up now. */
961 blv->where = Qnil;
962 SET_BLV_FOUND (blv, 0);
963 }
964
965 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
966 VALCONTENTS is the contents of its value cell,
967 which points to a struct Lisp_Buffer_Local_Value.
968
969 Return the value forwarded one step past the buffer-local stage.
970 This could be another forwarding pointer. */
971
972 static void
973 swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_Value *blv)
974 {
975 register Lisp_Object tem1;
976
977 eassert (blv == SYMBOL_BLV (symbol));
978
979 tem1 = blv->where;
980
981 if (NILP (tem1)
982 || (blv->frame_local
983 ? !EQ (selected_frame, tem1)
984 : current_buffer != XBUFFER (tem1)))
985 {
986
987 /* Unload the previously loaded binding. */
988 tem1 = blv->valcell;
989 if (blv->fwd)
990 SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
991 /* Choose the new binding. */
992 {
993 Lisp_Object var;
994 XSETSYMBOL (var, symbol);
995 if (blv->frame_local)
996 {
997 tem1 = assq_no_quit (var, XFRAME (selected_frame)->param_alist);
998 blv->where = selected_frame;
999 }
1000 else
1001 {
1002 tem1 = assq_no_quit (var, BVAR (current_buffer, local_var_alist));
1003 XSETBUFFER (blv->where, current_buffer);
1004 }
1005 }
1006 if (!(blv->found = !NILP (tem1)))
1007 tem1 = blv->defcell;
1008
1009 /* Load the new binding. */
1010 blv->valcell = tem1;
1011 if (blv->fwd)
1012 store_symval_forwarding (blv->fwd, BLV_VALUE (blv), NULL);
1013 }
1014 }
1015 \f
1016 /* Find the value of a symbol, returning Qunbound if it's not bound.
1017 This is helpful for code which just wants to get a variable's value
1018 if it has one, without signaling an error.
1019 Note that it must not be possible to quit
1020 within this function. Great care is required for this. */
1021
1022 Lisp_Object
1023 find_symbol_value (Lisp_Object symbol)
1024 {
1025 struct Lisp_Symbol *sym;
1026
1027 CHECK_SYMBOL (symbol);
1028 sym = XSYMBOL (symbol);
1029
1030 start:
1031 switch (sym->redirect)
1032 {
1033 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1034 case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym);
1035 case SYMBOL_LOCALIZED:
1036 {
1037 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1038 swap_in_symval_forwarding (sym, blv);
1039 return blv->fwd ? do_symval_forwarding (blv->fwd) : BLV_VALUE (blv);
1040 }
1041 /* FALLTHROUGH */
1042 case SYMBOL_FORWARDED:
1043 return do_symval_forwarding (SYMBOL_FWD (sym));
1044 default: abort ();
1045 }
1046 }
1047
1048 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
1049 doc: /* Return SYMBOL's value. Error if that is void. */)
1050 (Lisp_Object symbol)
1051 {
1052 Lisp_Object val;
1053
1054 val = find_symbol_value (symbol);
1055 if (!EQ (val, Qunbound))
1056 return val;
1057
1058 xsignal1 (Qvoid_variable, symbol);
1059 }
1060
1061 DEFUN ("set", Fset, Sset, 2, 2, 0,
1062 doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1063 (register Lisp_Object symbol, Lisp_Object newval)
1064 {
1065 set_internal (symbol, newval, Qnil, 0);
1066 return newval;
1067 }
1068
1069 /* Return 1 if SYMBOL currently has a let-binding
1070 which was made in the buffer that is now current. */
1071
1072 static int
1073 let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol)
1074 {
1075 struct specbinding *p;
1076
1077 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1078 if (p->func == NULL
1079 && CONSP (p->symbol))
1080 {
1081 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
1082 eassert (let_bound_symbol->redirect != SYMBOL_VARALIAS);
1083 if (symbol == let_bound_symbol
1084 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1085 break;
1086 }
1087
1088 return p >= specpdl;
1089 }
1090
1091 static int
1092 let_shadows_global_binding_p (Lisp_Object symbol)
1093 {
1094 struct specbinding *p;
1095
1096 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1097 if (p->func == NULL && EQ (p->symbol, symbol))
1098 break;
1099
1100 return p >= specpdl;
1101 }
1102
1103 /* Store the value NEWVAL into SYMBOL.
1104 If buffer/frame-locality is an issue, WHERE specifies which context to use.
1105 (nil stands for the current buffer/frame).
1106
1107 If BINDFLAG is zero, then if this symbol is supposed to become
1108 local in every buffer where it is set, then we make it local.
1109 If BINDFLAG is nonzero, we don't do that. */
1110
1111 void
1112 set_internal (register Lisp_Object symbol, register Lisp_Object newval, register Lisp_Object where, int bindflag)
1113 {
1114 int voide = EQ (newval, Qunbound);
1115 struct Lisp_Symbol *sym;
1116 Lisp_Object tem1;
1117
1118 /* If restoring in a dead buffer, do nothing. */
1119 /* if (BUFFERP (where) && NILP (XBUFFER (where)->name))
1120 return; */
1121
1122 CHECK_SYMBOL (symbol);
1123 if (SYMBOL_CONSTANT_P (symbol))
1124 {
1125 if (NILP (Fkeywordp (symbol))
1126 || !EQ (newval, Fsymbol_value (symbol)))
1127 xsignal1 (Qsetting_constant, symbol);
1128 else
1129 /* Allow setting keywords to their own value. */
1130 return;
1131 }
1132
1133 sym = XSYMBOL (symbol);
1134
1135 start:
1136 switch (sym->redirect)
1137 {
1138 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1139 case SYMBOL_PLAINVAL: SET_SYMBOL_VAL (sym , newval); return;
1140 case SYMBOL_LOCALIZED:
1141 {
1142 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1143 if (NILP (where))
1144 {
1145 if (blv->frame_local)
1146 where = selected_frame;
1147 else
1148 XSETBUFFER (where, current_buffer);
1149 }
1150 /* If the current buffer is not the buffer whose binding is
1151 loaded, or if there may be frame-local bindings and the frame
1152 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1153 the default binding is loaded, the loaded binding may be the
1154 wrong one. */
1155 if (!EQ (blv->where, where)
1156 /* Also unload a global binding (if the var is local_if_set). */
1157 || (EQ (blv->valcell, blv->defcell)))
1158 {
1159 /* The currently loaded binding is not necessarily valid.
1160 We need to unload it, and choose a new binding. */
1161
1162 /* Write out `realvalue' to the old loaded binding. */
1163 if (blv->fwd)
1164 SET_BLV_VALUE (blv, do_symval_forwarding (blv->fwd));
1165
1166 /* Find the new binding. */
1167 XSETSYMBOL (symbol, sym); /* May have changed via aliasing. */
1168 tem1 = Fassq (symbol,
1169 (blv->frame_local
1170 ? XFRAME (where)->param_alist
1171 : BVAR (XBUFFER (where), local_var_alist)));
1172 blv->where = where;
1173 blv->found = 1;
1174
1175 if (NILP (tem1))
1176 {
1177 /* This buffer still sees the default value. */
1178
1179 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1180 or if this is `let' rather than `set',
1181 make CURRENT-ALIST-ELEMENT point to itself,
1182 indicating that we're seeing the default value.
1183 Likewise if the variable has been let-bound
1184 in the current buffer. */
1185 if (bindflag || !blv->local_if_set
1186 || let_shadows_buffer_binding_p (sym))
1187 {
1188 blv->found = 0;
1189 tem1 = blv->defcell;
1190 }
1191 /* If it's a local_if_set, being set not bound,
1192 and we're not within a let that was made for this buffer,
1193 create a new buffer-local binding for the variable.
1194 That means, give this buffer a new assoc for a local value
1195 and load that binding. */
1196 else
1197 {
1198 /* local_if_set is only supported for buffer-local
1199 bindings, not for frame-local bindings. */
1200 eassert (!blv->frame_local);
1201 tem1 = Fcons (symbol, XCDR (blv->defcell));
1202 BVAR (XBUFFER (where), local_var_alist)
1203 = Fcons (tem1, BVAR (XBUFFER (where), local_var_alist));
1204 }
1205 }
1206
1207 /* Record which binding is now loaded. */
1208 blv->valcell = tem1;
1209 }
1210
1211 /* Store the new value in the cons cell. */
1212 SET_BLV_VALUE (blv, newval);
1213
1214 if (blv->fwd)
1215 {
1216 if (voide)
1217 /* If storing void (making the symbol void), forward only through
1218 buffer-local indicator, not through Lisp_Objfwd, etc. */
1219 blv->fwd = NULL;
1220 else
1221 store_symval_forwarding (blv->fwd, newval,
1222 BUFFERP (where)
1223 ? XBUFFER (where) : current_buffer);
1224 }
1225 break;
1226 }
1227 case SYMBOL_FORWARDED:
1228 {
1229 struct buffer *buf
1230 = BUFFERP (where) ? XBUFFER (where) : current_buffer;
1231 union Lisp_Fwd *innercontents = SYMBOL_FWD (sym);
1232 if (BUFFER_OBJFWDP (innercontents))
1233 {
1234 int offset = XBUFFER_OBJFWD (innercontents)->offset;
1235 int idx = PER_BUFFER_IDX (offset);
1236 if (idx > 0
1237 && !bindflag
1238 && !let_shadows_buffer_binding_p (sym))
1239 SET_PER_BUFFER_VALUE_P (buf, idx, 1);
1240 }
1241
1242 if (voide)
1243 { /* If storing void (making the symbol void), forward only through
1244 buffer-local indicator, not through Lisp_Objfwd, etc. */
1245 sym->redirect = SYMBOL_PLAINVAL;
1246 SET_SYMBOL_VAL (sym, newval);
1247 }
1248 else
1249 store_symval_forwarding (/* sym, */ innercontents, newval, buf);
1250 break;
1251 }
1252 default: abort ();
1253 }
1254 return;
1255 }
1256 \f
1257 /* Access or set a buffer-local symbol's default value. */
1258
1259 /* Return the default value of SYMBOL, but don't check for voidness.
1260 Return Qunbound if it is void. */
1261
1262 static Lisp_Object
1263 default_value (Lisp_Object symbol)
1264 {
1265 struct Lisp_Symbol *sym;
1266
1267 CHECK_SYMBOL (symbol);
1268 sym = XSYMBOL (symbol);
1269
1270 start:
1271 switch (sym->redirect)
1272 {
1273 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1274 case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym);
1275 case SYMBOL_LOCALIZED:
1276 {
1277 /* If var is set up for a buffer that lacks a local value for it,
1278 the current value is nominally the default value.
1279 But the `realvalue' slot may be more up to date, since
1280 ordinary setq stores just that slot. So use that. */
1281 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1282 if (blv->fwd && EQ (blv->valcell, blv->defcell))
1283 return do_symval_forwarding (blv->fwd);
1284 else
1285 return XCDR (blv->defcell);
1286 }
1287 case SYMBOL_FORWARDED:
1288 {
1289 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
1290
1291 /* For a built-in buffer-local variable, get the default value
1292 rather than letting do_symval_forwarding get the current value. */
1293 if (BUFFER_OBJFWDP (valcontents))
1294 {
1295 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1296 if (PER_BUFFER_IDX (offset) != 0)
1297 return PER_BUFFER_DEFAULT (offset);
1298 }
1299
1300 /* For other variables, get the current value. */
1301 return do_symval_forwarding (valcontents);
1302 }
1303 default: abort ();
1304 }
1305 }
1306
1307 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1308 doc: /* Return t if SYMBOL has a non-void default value.
1309 This is the value that is seen in buffers that do not have their own values
1310 for this variable. */)
1311 (Lisp_Object symbol)
1312 {
1313 register Lisp_Object value;
1314
1315 value = default_value (symbol);
1316 return (EQ (value, Qunbound) ? Qnil : Qt);
1317 }
1318
1319 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1320 doc: /* Return SYMBOL's default value.
1321 This is the value that is seen in buffers that do not have their own values
1322 for this variable. The default value is meaningful for variables with
1323 local bindings in certain buffers. */)
1324 (Lisp_Object symbol)
1325 {
1326 register Lisp_Object value;
1327
1328 value = default_value (symbol);
1329 if (!EQ (value, Qunbound))
1330 return value;
1331
1332 xsignal1 (Qvoid_variable, symbol);
1333 }
1334
1335 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1336 doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1337 The default value is seen in buffers that do not have their own values
1338 for this variable. */)
1339 (Lisp_Object symbol, Lisp_Object value)
1340 {
1341 struct Lisp_Symbol *sym;
1342
1343 CHECK_SYMBOL (symbol);
1344 if (SYMBOL_CONSTANT_P (symbol))
1345 {
1346 if (NILP (Fkeywordp (symbol))
1347 || !EQ (value, Fdefault_value (symbol)))
1348 xsignal1 (Qsetting_constant, symbol);
1349 else
1350 /* Allow setting keywords to their own value. */
1351 return value;
1352 }
1353 sym = XSYMBOL (symbol);
1354
1355 start:
1356 switch (sym->redirect)
1357 {
1358 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1359 case SYMBOL_PLAINVAL: return Fset (symbol, value);
1360 case SYMBOL_LOCALIZED:
1361 {
1362 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1363
1364 /* Store new value into the DEFAULT-VALUE slot. */
1365 XSETCDR (blv->defcell, value);
1366
1367 /* If the default binding is now loaded, set the REALVALUE slot too. */
1368 if (blv->fwd && EQ (blv->defcell, blv->valcell))
1369 store_symval_forwarding (blv->fwd, value, NULL);
1370 return value;
1371 }
1372 case SYMBOL_FORWARDED:
1373 {
1374 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
1375
1376 /* Handle variables like case-fold-search that have special slots
1377 in the buffer.
1378 Make them work apparently like Lisp_Buffer_Local_Value variables. */
1379 if (BUFFER_OBJFWDP (valcontents))
1380 {
1381 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1382 int idx = PER_BUFFER_IDX (offset);
1383
1384 PER_BUFFER_DEFAULT (offset) = value;
1385
1386 /* If this variable is not always local in all buffers,
1387 set it in the buffers that don't nominally have a local value. */
1388 if (idx > 0)
1389 {
1390 struct buffer *b;
1391
1392 for (b = all_buffers; b; b = b->header.next.buffer)
1393 if (!PER_BUFFER_VALUE_P (b, idx))
1394 PER_BUFFER_VALUE (b, offset) = value;
1395 }
1396 return value;
1397 }
1398 else
1399 return Fset (symbol, value);
1400 }
1401 default: abort ();
1402 }
1403 }
1404
1405 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
1406 doc: /* Set the default value of variable VAR to VALUE.
1407 VAR, the variable name, is literal (not evaluated);
1408 VALUE is an expression: it is evaluated and its value returned.
1409 The default value of a variable is seen in buffers
1410 that do not have their own values for the variable.
1411
1412 More generally, you can use multiple variables and values, as in
1413 (setq-default VAR VALUE VAR VALUE...)
1414 This sets each VAR's default value to the corresponding VALUE.
1415 The VALUE for the Nth VAR can refer to the new default values
1416 of previous VARs.
1417 usage: (setq-default [VAR VALUE]...) */)
1418 (Lisp_Object args)
1419 {
1420 register Lisp_Object args_left;
1421 register Lisp_Object val, symbol;
1422 struct gcpro gcpro1;
1423
1424 if (NILP (args))
1425 return Qnil;
1426
1427 args_left = args;
1428 GCPRO1 (args);
1429
1430 do
1431 {
1432 val = eval_sub (Fcar (Fcdr (args_left)));
1433 symbol = XCAR (args_left);
1434 Fset_default (symbol, val);
1435 args_left = Fcdr (XCDR (args_left));
1436 }
1437 while (!NILP (args_left));
1438
1439 UNGCPRO;
1440 return val;
1441 }
1442 \f
1443 /* Lisp functions for creating and removing buffer-local variables. */
1444
1445 union Lisp_Val_Fwd
1446 {
1447 Lisp_Object value;
1448 union Lisp_Fwd *fwd;
1449 };
1450
1451 static struct Lisp_Buffer_Local_Value *
1452 make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents)
1453 {
1454 struct Lisp_Buffer_Local_Value *blv
1455 = xmalloc (sizeof (struct Lisp_Buffer_Local_Value));
1456 Lisp_Object symbol;
1457 Lisp_Object tem;
1458
1459 XSETSYMBOL (symbol, sym);
1460 tem = Fcons (symbol, (forwarded
1461 ? do_symval_forwarding (valcontents.fwd)
1462 : valcontents.value));
1463
1464 /* Buffer_Local_Values cannot have as realval a buffer-local
1465 or keyboard-local forwarding. */
1466 eassert (!(forwarded && BUFFER_OBJFWDP (valcontents.fwd)));
1467 eassert (!(forwarded && KBOARD_OBJFWDP (valcontents.fwd)));
1468 blv->fwd = forwarded ? valcontents.fwd : NULL;
1469 blv->where = Qnil;
1470 blv->frame_local = 0;
1471 blv->local_if_set = 0;
1472 blv->defcell = tem;
1473 blv->valcell = tem;
1474 SET_BLV_FOUND (blv, 0);
1475 return blv;
1476 }
1477
1478 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local,
1479 Smake_variable_buffer_local, 1, 1, "vMake Variable Buffer Local: ",
1480 doc: /* Make VARIABLE become buffer-local whenever it is set.
1481 At any time, the value for the current buffer is in effect,
1482 unless the variable has never been set in this buffer,
1483 in which case the default value is in effect.
1484 Note that binding the variable with `let', or setting it while
1485 a `let'-style binding made in this buffer is in effect,
1486 does not make the variable buffer-local. Return VARIABLE.
1487
1488 In most cases it is better to use `make-local-variable',
1489 which makes a variable local in just one buffer.
1490
1491 The function `default-value' gets the default value and `set-default' sets it. */)
1492 (register Lisp_Object variable)
1493 {
1494 struct Lisp_Symbol *sym;
1495 struct Lisp_Buffer_Local_Value *blv = NULL;
1496 union Lisp_Val_Fwd valcontents IF_LINT (= {0});
1497 int forwarded IF_LINT (= 0);
1498
1499 CHECK_SYMBOL (variable);
1500 sym = XSYMBOL (variable);
1501
1502 start:
1503 switch (sym->redirect)
1504 {
1505 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1506 case SYMBOL_PLAINVAL:
1507 forwarded = 0; valcontents.value = SYMBOL_VAL (sym);
1508 if (EQ (valcontents.value, Qunbound))
1509 valcontents.value = Qnil;
1510 break;
1511 case SYMBOL_LOCALIZED:
1512 blv = SYMBOL_BLV (sym);
1513 if (blv->frame_local)
1514 error ("Symbol %s may not be buffer-local",
1515 SDATA (SYMBOL_NAME (variable)));
1516 break;
1517 case SYMBOL_FORWARDED:
1518 forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym);
1519 if (KBOARD_OBJFWDP (valcontents.fwd))
1520 error ("Symbol %s may not be buffer-local",
1521 SDATA (SYMBOL_NAME (variable)));
1522 else if (BUFFER_OBJFWDP (valcontents.fwd))
1523 return variable;
1524 break;
1525 default: abort ();
1526 }
1527
1528 if (sym->constant)
1529 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
1530
1531 if (!blv)
1532 {
1533 blv = make_blv (sym, forwarded, valcontents);
1534 sym->redirect = SYMBOL_LOCALIZED;
1535 SET_SYMBOL_BLV (sym, blv);
1536 {
1537 Lisp_Object symbol;
1538 XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */
1539 if (let_shadows_global_binding_p (symbol))
1540 message ("Making %s buffer-local while let-bound!",
1541 SDATA (SYMBOL_NAME (variable)));
1542 }
1543 }
1544
1545 blv->local_if_set = 1;
1546 return variable;
1547 }
1548
1549 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1550 1, 1, "vMake Local Variable: ",
1551 doc: /* Make VARIABLE have a separate value in the current buffer.
1552 Other buffers will continue to share a common default value.
1553 \(The buffer-local value of VARIABLE starts out as the same value
1554 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1555 Return VARIABLE.
1556
1557 If the variable is already arranged to become local when set,
1558 this function causes a local value to exist for this buffer,
1559 just as setting the variable would do.
1560
1561 This function returns VARIABLE, and therefore
1562 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1563 works.
1564
1565 See also `make-variable-buffer-local'.
1566
1567 Do not use `make-local-variable' to make a hook variable buffer-local.
1568 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1569 (register Lisp_Object variable)
1570 {
1571 register Lisp_Object tem;
1572 int forwarded IF_LINT (= 0);
1573 union Lisp_Val_Fwd valcontents IF_LINT (= {0});
1574 struct Lisp_Symbol *sym;
1575 struct Lisp_Buffer_Local_Value *blv = NULL;
1576
1577 CHECK_SYMBOL (variable);
1578 sym = XSYMBOL (variable);
1579
1580 start:
1581 switch (sym->redirect)
1582 {
1583 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1584 case SYMBOL_PLAINVAL:
1585 forwarded = 0; valcontents.value = SYMBOL_VAL (sym); break;
1586 case SYMBOL_LOCALIZED:
1587 blv = SYMBOL_BLV (sym);
1588 if (blv->frame_local)
1589 error ("Symbol %s may not be buffer-local",
1590 SDATA (SYMBOL_NAME (variable)));
1591 break;
1592 case SYMBOL_FORWARDED:
1593 forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym);
1594 if (KBOARD_OBJFWDP (valcontents.fwd))
1595 error ("Symbol %s may not be buffer-local",
1596 SDATA (SYMBOL_NAME (variable)));
1597 break;
1598 default: abort ();
1599 }
1600
1601 if (sym->constant)
1602 error ("Symbol %s may not be buffer-local",
1603 SDATA (SYMBOL_NAME (variable)));
1604
1605 if (blv ? blv->local_if_set
1606 : (forwarded && BUFFER_OBJFWDP (valcontents.fwd)))
1607 {
1608 tem = Fboundp (variable);
1609 /* Make sure the symbol has a local value in this particular buffer,
1610 by setting it to the same value it already has. */
1611 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1612 return variable;
1613 }
1614 if (!blv)
1615 {
1616 blv = make_blv (sym, forwarded, valcontents);
1617 sym->redirect = SYMBOL_LOCALIZED;
1618 SET_SYMBOL_BLV (sym, blv);
1619 {
1620 Lisp_Object symbol;
1621 XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */
1622 if (let_shadows_global_binding_p (symbol))
1623 message ("Making %s local to %s while let-bound!",
1624 SDATA (SYMBOL_NAME (variable)),
1625 SDATA (BVAR (current_buffer, name)));
1626 }
1627 }
1628
1629 /* Make sure this buffer has its own value of symbol. */
1630 XSETSYMBOL (variable, sym); /* Update in case of aliasing. */
1631 tem = Fassq (variable, BVAR (current_buffer, local_var_alist));
1632 if (NILP (tem))
1633 {
1634 if (let_shadows_buffer_binding_p (sym))
1635 message ("Making %s buffer-local while locally let-bound!",
1636 SDATA (SYMBOL_NAME (variable)));
1637
1638 /* Swap out any local binding for some other buffer, and make
1639 sure the current value is permanently recorded, if it's the
1640 default value. */
1641 find_symbol_value (variable);
1642
1643 BVAR (current_buffer, local_var_alist)
1644 = Fcons (Fcons (variable, XCDR (blv->defcell)),
1645 BVAR (current_buffer, local_var_alist));
1646
1647 /* Make sure symbol does not think it is set up for this buffer;
1648 force it to look once again for this buffer's value. */
1649 if (current_buffer == XBUFFER (blv->where))
1650 blv->where = Qnil;
1651 /* blv->valcell = blv->defcell;
1652 * SET_BLV_FOUND (blv, 0); */
1653 blv->found = 0;
1654 }
1655
1656 /* If the symbol forwards into a C variable, then load the binding
1657 for this buffer now. If C code modifies the variable before we
1658 load the binding in, then that new value will clobber the default
1659 binding the next time we unload it. */
1660 if (blv->fwd)
1661 swap_in_symval_forwarding (sym, blv);
1662
1663 return variable;
1664 }
1665
1666 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1667 1, 1, "vKill Local Variable: ",
1668 doc: /* Make VARIABLE no longer have a separate value in the current buffer.
1669 From now on the default value will apply in this buffer. Return VARIABLE. */)
1670 (register Lisp_Object variable)
1671 {
1672 register Lisp_Object tem;
1673 struct Lisp_Buffer_Local_Value *blv;
1674 struct Lisp_Symbol *sym;
1675
1676 CHECK_SYMBOL (variable);
1677 sym = XSYMBOL (variable);
1678
1679 start:
1680 switch (sym->redirect)
1681 {
1682 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1683 case SYMBOL_PLAINVAL: return variable;
1684 case SYMBOL_FORWARDED:
1685 {
1686 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
1687 if (BUFFER_OBJFWDP (valcontents))
1688 {
1689 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1690 int idx = PER_BUFFER_IDX (offset);
1691
1692 if (idx > 0)
1693 {
1694 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
1695 PER_BUFFER_VALUE (current_buffer, offset)
1696 = PER_BUFFER_DEFAULT (offset);
1697 }
1698 }
1699 return variable;
1700 }
1701 case SYMBOL_LOCALIZED:
1702 blv = SYMBOL_BLV (sym);
1703 if (blv->frame_local)
1704 return variable;
1705 break;
1706 default: abort ();
1707 }
1708
1709 /* Get rid of this buffer's alist element, if any. */
1710 XSETSYMBOL (variable, sym); /* Propagate variable indirection. */
1711 tem = Fassq (variable, BVAR (current_buffer, local_var_alist));
1712 if (!NILP (tem))
1713 BVAR (current_buffer, local_var_alist)
1714 = Fdelq (tem, BVAR (current_buffer, local_var_alist));
1715
1716 /* If the symbol is set up with the current buffer's binding
1717 loaded, recompute its value. We have to do it now, or else
1718 forwarded objects won't work right. */
1719 {
1720 Lisp_Object buf; XSETBUFFER (buf, current_buffer);
1721 if (EQ (buf, blv->where))
1722 {
1723 blv->where = Qnil;
1724 /* blv->valcell = blv->defcell;
1725 * SET_BLV_FOUND (blv, 0); */
1726 blv->found = 0;
1727 find_symbol_value (variable);
1728 }
1729 }
1730
1731 return variable;
1732 }
1733
1734 /* Lisp functions for creating and removing buffer-local variables. */
1735
1736 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1737 when/if this is removed. */
1738
1739 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
1740 1, 1, "vMake Variable Frame Local: ",
1741 doc: /* Enable VARIABLE to have frame-local bindings.
1742 This does not create any frame-local bindings for VARIABLE,
1743 it just makes them possible.
1744
1745 A frame-local binding is actually a frame parameter value.
1746 If a frame F has a value for the frame parameter named VARIABLE,
1747 that also acts as a frame-local binding for VARIABLE in F--
1748 provided this function has been called to enable VARIABLE
1749 to have frame-local bindings at all.
1750
1751 The only way to create a frame-local binding for VARIABLE in a frame
1752 is to set the VARIABLE frame parameter of that frame. See
1753 `modify-frame-parameters' for how to set frame parameters.
1754
1755 Note that since Emacs 23.1, variables cannot be both buffer-local and
1756 frame-local any more (buffer-local bindings used to take precedence over
1757 frame-local bindings). */)
1758 (register Lisp_Object variable)
1759 {
1760 int forwarded;
1761 union Lisp_Val_Fwd valcontents;
1762 struct Lisp_Symbol *sym;
1763 struct Lisp_Buffer_Local_Value *blv = NULL;
1764
1765 CHECK_SYMBOL (variable);
1766 sym = XSYMBOL (variable);
1767
1768 start:
1769 switch (sym->redirect)
1770 {
1771 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1772 case SYMBOL_PLAINVAL:
1773 forwarded = 0; valcontents.value = SYMBOL_VAL (sym);
1774 if (EQ (valcontents.value, Qunbound))
1775 valcontents.value = Qnil;
1776 break;
1777 case SYMBOL_LOCALIZED:
1778 if (SYMBOL_BLV (sym)->frame_local)
1779 return variable;
1780 else
1781 error ("Symbol %s may not be frame-local",
1782 SDATA (SYMBOL_NAME (variable)));
1783 case SYMBOL_FORWARDED:
1784 forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym);
1785 if (KBOARD_OBJFWDP (valcontents.fwd) || BUFFER_OBJFWDP (valcontents.fwd))
1786 error ("Symbol %s may not be frame-local",
1787 SDATA (SYMBOL_NAME (variable)));
1788 break;
1789 default: abort ();
1790 }
1791
1792 if (sym->constant)
1793 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable)));
1794
1795 blv = make_blv (sym, forwarded, valcontents);
1796 blv->frame_local = 1;
1797 sym->redirect = SYMBOL_LOCALIZED;
1798 SET_SYMBOL_BLV (sym, blv);
1799 {
1800 Lisp_Object symbol;
1801 XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */
1802 if (let_shadows_global_binding_p (symbol))
1803 message ("Making %s frame-local while let-bound!",
1804 SDATA (SYMBOL_NAME (variable)));
1805 }
1806 return variable;
1807 }
1808
1809 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1810 1, 2, 0,
1811 doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1812 BUFFER defaults to the current buffer. */)
1813 (register Lisp_Object variable, Lisp_Object buffer)
1814 {
1815 register struct buffer *buf;
1816 struct Lisp_Symbol *sym;
1817
1818 if (NILP (buffer))
1819 buf = current_buffer;
1820 else
1821 {
1822 CHECK_BUFFER (buffer);
1823 buf = XBUFFER (buffer);
1824 }
1825
1826 CHECK_SYMBOL (variable);
1827 sym = XSYMBOL (variable);
1828
1829 start:
1830 switch (sym->redirect)
1831 {
1832 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1833 case SYMBOL_PLAINVAL: return Qnil;
1834 case SYMBOL_LOCALIZED:
1835 {
1836 Lisp_Object tail, elt, tmp;
1837 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1838 XSETBUFFER (tmp, buf);
1839 XSETSYMBOL (variable, sym); /* Update in case of aliasing. */
1840
1841 for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail))
1842 {
1843 elt = XCAR (tail);
1844 if (EQ (variable, XCAR (elt)))
1845 {
1846 eassert (!blv->frame_local);
1847 eassert (BLV_FOUND (blv) || !EQ (blv->where, tmp));
1848 return Qt;
1849 }
1850 }
1851 eassert (!BLV_FOUND (blv) || !EQ (blv->where, tmp));
1852 return Qnil;
1853 }
1854 case SYMBOL_FORWARDED:
1855 {
1856 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
1857 if (BUFFER_OBJFWDP (valcontents))
1858 {
1859 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1860 int idx = PER_BUFFER_IDX (offset);
1861 if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1862 return Qt;
1863 }
1864 return Qnil;
1865 }
1866 default: abort ();
1867 }
1868 }
1869
1870 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
1871 1, 2, 0,
1872 doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1873 More precisely, this means that setting the variable \(with `set' or`setq'),
1874 while it does not have a `let'-style binding that was made in BUFFER,
1875 will produce a buffer local binding. See Info node
1876 `(elisp)Creating Buffer-Local'.
1877 BUFFER defaults to the current buffer. */)
1878 (register Lisp_Object variable, Lisp_Object buffer)
1879 {
1880 struct Lisp_Symbol *sym;
1881
1882 CHECK_SYMBOL (variable);
1883 sym = XSYMBOL (variable);
1884
1885 start:
1886 switch (sym->redirect)
1887 {
1888 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1889 case SYMBOL_PLAINVAL: return Qnil;
1890 case SYMBOL_LOCALIZED:
1891 {
1892 struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym);
1893 if (blv->local_if_set)
1894 return Qt;
1895 XSETSYMBOL (variable, sym); /* Update in case of aliasing. */
1896 return Flocal_variable_p (variable, buffer);
1897 }
1898 case SYMBOL_FORWARDED:
1899 /* All BUFFER_OBJFWD slots become local if they are set. */
1900 return (BUFFER_OBJFWDP (SYMBOL_FWD (sym)) ? Qt : Qnil);
1901 default: abort ();
1902 }
1903 }
1904
1905 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1906 1, 1, 0,
1907 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1908 If the current binding is buffer-local, the value is the current buffer.
1909 If the current binding is frame-local, the value is the selected frame.
1910 If the current binding is global (the default), the value is nil. */)
1911 (register Lisp_Object variable)
1912 {
1913 struct Lisp_Symbol *sym;
1914
1915 CHECK_SYMBOL (variable);
1916 sym = XSYMBOL (variable);
1917
1918 /* Make sure the current binding is actually swapped in. */
1919 find_symbol_value (variable);
1920
1921 start:
1922 switch (sym->redirect)
1923 {
1924 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
1925 case SYMBOL_PLAINVAL: return Qnil;
1926 case SYMBOL_FORWARDED:
1927 {
1928 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
1929 if (KBOARD_OBJFWDP (valcontents))
1930 return Fframe_terminal (Fselected_frame ());
1931 else if (!BUFFER_OBJFWDP (valcontents))
1932 return Qnil;
1933 }
1934 /* FALLTHROUGH */
1935 case SYMBOL_LOCALIZED:
1936 /* For a local variable, record both the symbol and which
1937 buffer's or frame's value we are saving. */
1938 if (!NILP (Flocal_variable_p (variable, Qnil)))
1939 return Fcurrent_buffer ();
1940 else if (sym->redirect == SYMBOL_LOCALIZED
1941 && BLV_FOUND (SYMBOL_BLV (sym)))
1942 return SYMBOL_BLV (sym)->where;
1943 else
1944 return Qnil;
1945 default: abort ();
1946 }
1947 }
1948
1949 /* This code is disabled now that we use the selected frame to return
1950 keyboard-local-values. */
1951 #if 0
1952 extern struct terminal *get_terminal (Lisp_Object display, int);
1953
1954 DEFUN ("terminal-local-value", Fterminal_local_value,
1955 Sterminal_local_value, 2, 2, 0,
1956 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
1957 If SYMBOL is not a terminal-local variable, then return its normal
1958 value, like `symbol-value'.
1959
1960 TERMINAL may be a terminal object, a frame, or nil (meaning the
1961 selected frame's terminal device). */)
1962 (Lisp_Object symbol, Lisp_Object terminal)
1963 {
1964 Lisp_Object result;
1965 struct terminal *t = get_terminal (terminal, 1);
1966 push_kboard (t->kboard);
1967 result = Fsymbol_value (symbol);
1968 pop_kboard ();
1969 return result;
1970 }
1971
1972 DEFUN ("set-terminal-local-value", Fset_terminal_local_value,
1973 Sset_terminal_local_value, 3, 3, 0,
1974 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
1975 If VARIABLE is not a terminal-local variable, then set its normal
1976 binding, like `set'.
1977
1978 TERMINAL may be a terminal object, a frame, or nil (meaning the
1979 selected frame's terminal device). */)
1980 (Lisp_Object symbol, Lisp_Object terminal, Lisp_Object value)
1981 {
1982 Lisp_Object result;
1983 struct terminal *t = get_terminal (terminal, 1);
1984 push_kboard (d->kboard);
1985 result = Fset (symbol, value);
1986 pop_kboard ();
1987 return result;
1988 }
1989 #endif
1990 \f
1991 /* Find the function at the end of a chain of symbol function indirections. */
1992
1993 /* If OBJECT is a symbol, find the end of its function chain and
1994 return the value found there. If OBJECT is not a symbol, just
1995 return it. If there is a cycle in the function chain, signal a
1996 cyclic-function-indirection error.
1997
1998 This is like Findirect_function, except that it doesn't signal an
1999 error if the chain ends up unbound. */
2000 Lisp_Object
2001 indirect_function (register Lisp_Object object)
2002 {
2003 Lisp_Object tortoise, hare;
2004
2005 hare = tortoise = object;
2006
2007 for (;;)
2008 {
2009 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2010 break;
2011 hare = XSYMBOL (hare)->function;
2012 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2013 break;
2014 hare = XSYMBOL (hare)->function;
2015
2016 tortoise = XSYMBOL (tortoise)->function;
2017
2018 if (EQ (hare, tortoise))
2019 xsignal1 (Qcyclic_function_indirection, object);
2020 }
2021
2022 return hare;
2023 }
2024
2025 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0,
2026 doc: /* Return the function at the end of OBJECT's function chain.
2027 If OBJECT is not a symbol, just return it. Otherwise, follow all
2028 function indirections to find the final function binding and return it.
2029 If the final symbol in the chain is unbound, signal a void-function error.
2030 Optional arg NOERROR non-nil means to return nil instead of signalling.
2031 Signal a cyclic-function-indirection error if there is a loop in the
2032 function chain of symbols. */)
2033 (register Lisp_Object object, Lisp_Object noerror)
2034 {
2035 Lisp_Object result;
2036
2037 /* Optimize for no indirection. */
2038 result = object;
2039 if (SYMBOLP (result) && !EQ (result, Qunbound)
2040 && (result = XSYMBOL (result)->function, SYMBOLP (result)))
2041 result = indirect_function (result);
2042 if (!EQ (result, Qunbound))
2043 return result;
2044
2045 if (NILP (noerror))
2046 xsignal1 (Qvoid_function, object);
2047
2048 return Qnil;
2049 }
2050 \f
2051 /* Extract and set vector and string elements */
2052
2053 DEFUN ("aref", Faref, Saref, 2, 2, 0,
2054 doc: /* Return the element of ARRAY at index IDX.
2055 ARRAY may be a vector, a string, a char-table, a bool-vector,
2056 or a byte-code object. IDX starts at 0. */)
2057 (register Lisp_Object array, Lisp_Object idx)
2058 {
2059 register EMACS_INT idxval;
2060
2061 CHECK_NUMBER (idx);
2062 idxval = XINT (idx);
2063 if (STRINGP (array))
2064 {
2065 int c;
2066 EMACS_INT idxval_byte;
2067
2068 if (idxval < 0 || idxval >= SCHARS (array))
2069 args_out_of_range (array, idx);
2070 if (! STRING_MULTIBYTE (array))
2071 return make_number ((unsigned char) SREF (array, idxval));
2072 idxval_byte = string_char_to_byte (array, idxval);
2073
2074 c = STRING_CHAR (SDATA (array) + idxval_byte);
2075 return make_number (c);
2076 }
2077 else if (BOOL_VECTOR_P (array))
2078 {
2079 int val;
2080
2081 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2082 args_out_of_range (array, idx);
2083
2084 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2085 return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
2086 }
2087 else if (CHAR_TABLE_P (array))
2088 {
2089 CHECK_CHARACTER (idx);
2090 return CHAR_TABLE_REF (array, idxval);
2091 }
2092 else
2093 {
2094 int size = 0;
2095 if (VECTORP (array))
2096 size = XVECTOR_SIZE (array);
2097 else if (COMPILEDP (array))
2098 size = XVECTOR_SIZE (array) & PSEUDOVECTOR_SIZE_MASK;
2099 else
2100 wrong_type_argument (Qarrayp, array);
2101
2102 if (idxval < 0 || idxval >= size)
2103 args_out_of_range (array, idx);
2104 return AREF (array, idxval);
2105 }
2106 }
2107
2108 DEFUN ("aset", Faset, Saset, 3, 3, 0,
2109 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2110 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2111 bool-vector. IDX starts at 0. */)
2112 (register Lisp_Object array, Lisp_Object idx, Lisp_Object newelt)
2113 {
2114 register EMACS_INT idxval;
2115
2116 CHECK_NUMBER (idx);
2117 idxval = XINT (idx);
2118 CHECK_ARRAY (array, Qarrayp);
2119 CHECK_IMPURE (array);
2120
2121 if (VECTORP (array))
2122 {
2123 if (idxval < 0 || idxval >= XVECTOR_SIZE (array))
2124 args_out_of_range (array, idx);
2125 XVECTOR (array)->contents[idxval] = newelt;
2126 }
2127 else if (BOOL_VECTOR_P (array))
2128 {
2129 int val;
2130
2131 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2132 args_out_of_range (array, idx);
2133
2134 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2135
2136 if (! NILP (newelt))
2137 val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
2138 else
2139 val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
2140 XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
2141 }
2142 else if (CHAR_TABLE_P (array))
2143 {
2144 CHECK_CHARACTER (idx);
2145 CHAR_TABLE_SET (array, idxval, newelt);
2146 }
2147 else if (STRING_MULTIBYTE (array))
2148 {
2149 EMACS_INT idxval_byte, prev_bytes, new_bytes, nbytes;
2150 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2151
2152 if (idxval < 0 || idxval >= SCHARS (array))
2153 args_out_of_range (array, idx);
2154 CHECK_CHARACTER (newelt);
2155
2156 nbytes = SBYTES (array);
2157
2158 idxval_byte = string_char_to_byte (array, idxval);
2159 p1 = SDATA (array) + idxval_byte;
2160 prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2161 new_bytes = CHAR_STRING (XINT (newelt), p0);
2162 if (prev_bytes != new_bytes)
2163 {
2164 /* We must relocate the string data. */
2165 EMACS_INT nchars = SCHARS (array);
2166 unsigned char *str;
2167 USE_SAFE_ALLOCA;
2168
2169 SAFE_ALLOCA (str, unsigned char *, nbytes);
2170 memcpy (str, SDATA (array), nbytes);
2171 allocate_string_data (XSTRING (array), nchars,
2172 nbytes + new_bytes - prev_bytes);
2173 memcpy (SDATA (array), str, idxval_byte);
2174 p1 = SDATA (array) + idxval_byte;
2175 memcpy (p1 + new_bytes, str + idxval_byte + prev_bytes,
2176 nbytes - (idxval_byte + prev_bytes));
2177 SAFE_FREE ();
2178 clear_string_char_byte_cache ();
2179 }
2180 while (new_bytes--)
2181 *p1++ = *p0++;
2182 }
2183 else
2184 {
2185 if (idxval < 0 || idxval >= SCHARS (array))
2186 args_out_of_range (array, idx);
2187 CHECK_NUMBER (newelt);
2188
2189 if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
2190 {
2191 int i;
2192
2193 for (i = SBYTES (array) - 1; i >= 0; i--)
2194 if (SREF (array, i) >= 0x80)
2195 args_out_of_range (array, newelt);
2196 /* ARRAY is an ASCII string. Convert it to a multibyte
2197 string, and try `aset' again. */
2198 STRING_SET_MULTIBYTE (array);
2199 return Faset (array, idx, newelt);
2200 }
2201 SSET (array, idxval, XINT (newelt));
2202 }
2203
2204 return newelt;
2205 }
2206 \f
2207 /* Arithmetic functions */
2208
2209 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
2210
2211 static Lisp_Object
2212 arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison)
2213 {
2214 double f1 = 0, f2 = 0;
2215 int floatp = 0;
2216
2217 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1);
2218 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2);
2219
2220 if (FLOATP (num1) || FLOATP (num2))
2221 {
2222 floatp = 1;
2223 f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
2224 f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
2225 }
2226
2227 switch (comparison)
2228 {
2229 case equal:
2230 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
2231 return Qt;
2232 return Qnil;
2233
2234 case notequal:
2235 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
2236 return Qt;
2237 return Qnil;
2238
2239 case less:
2240 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
2241 return Qt;
2242 return Qnil;
2243
2244 case less_or_equal:
2245 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
2246 return Qt;
2247 return Qnil;
2248
2249 case grtr:
2250 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
2251 return Qt;
2252 return Qnil;
2253
2254 case grtr_or_equal:
2255 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
2256 return Qt;
2257 return Qnil;
2258
2259 default:
2260 abort ();
2261 }
2262 }
2263
2264 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
2265 doc: /* Return t if two args, both numbers or markers, are equal. */)
2266 (register Lisp_Object num1, Lisp_Object num2)
2267 {
2268 return arithcompare (num1, num2, equal);
2269 }
2270
2271 DEFUN ("<", Flss, Slss, 2, 2, 0,
2272 doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2273 (register Lisp_Object num1, Lisp_Object num2)
2274 {
2275 return arithcompare (num1, num2, less);
2276 }
2277
2278 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
2279 doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2280 (register Lisp_Object num1, Lisp_Object num2)
2281 {
2282 return arithcompare (num1, num2, grtr);
2283 }
2284
2285 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
2286 doc: /* Return t if first arg is less than or equal to second arg.
2287 Both must be numbers or markers. */)
2288 (register Lisp_Object num1, Lisp_Object num2)
2289 {
2290 return arithcompare (num1, num2, less_or_equal);
2291 }
2292
2293 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
2294 doc: /* Return t if first arg is greater than or equal to second arg.
2295 Both must be numbers or markers. */)
2296 (register Lisp_Object num1, Lisp_Object num2)
2297 {
2298 return arithcompare (num1, num2, grtr_or_equal);
2299 }
2300
2301 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
2302 doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2303 (register Lisp_Object num1, Lisp_Object num2)
2304 {
2305 return arithcompare (num1, num2, notequal);
2306 }
2307
2308 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
2309 doc: /* Return t if NUMBER is zero. */)
2310 (register Lisp_Object number)
2311 {
2312 CHECK_NUMBER_OR_FLOAT (number);
2313
2314 if (FLOATP (number))
2315 {
2316 if (XFLOAT_DATA (number) == 0.0)
2317 return Qt;
2318 return Qnil;
2319 }
2320
2321 if (!XINT (number))
2322 return Qt;
2323 return Qnil;
2324 }
2325 \f
2326 /* Convert between long values and pairs of Lisp integers.
2327 Note that long_to_cons returns a single Lisp integer
2328 when the value fits in one. */
2329
2330 Lisp_Object
2331 long_to_cons (long unsigned int i)
2332 {
2333 unsigned long top = i >> 16;
2334 unsigned int bot = i & 0xFFFF;
2335 if (top == 0)
2336 return make_number (bot);
2337 if (top == (unsigned long)-1 >> 16)
2338 return Fcons (make_number (-1), make_number (bot));
2339 return Fcons (make_number (top), make_number (bot));
2340 }
2341
2342 unsigned long
2343 cons_to_long (Lisp_Object c)
2344 {
2345 Lisp_Object top, bot;
2346 if (INTEGERP (c))
2347 return XINT (c);
2348 top = XCAR (c);
2349 bot = XCDR (c);
2350 if (CONSP (bot))
2351 bot = XCAR (bot);
2352 return ((XINT (top) << 16) | XINT (bot));
2353 }
2354 \f
2355 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
2356 doc: /* Return the decimal representation of NUMBER as a string.
2357 Uses a minus sign if negative.
2358 NUMBER may be an integer or a floating point number. */)
2359 (Lisp_Object number)
2360 {
2361 char buffer[VALBITS];
2362
2363 CHECK_NUMBER_OR_FLOAT (number);
2364
2365 if (FLOATP (number))
2366 {
2367 char pigbuf[FLOAT_TO_STRING_BUFSIZE];
2368
2369 float_to_string (pigbuf, XFLOAT_DATA (number));
2370 return build_string (pigbuf);
2371 }
2372
2373 sprintf (buffer, "%"pI"d", XINT (number));
2374 return build_string (buffer);
2375 }
2376
2377 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
2378 doc: /* Parse STRING as a decimal number and return the number.
2379 This parses both integers and floating point numbers.
2380 It ignores leading spaces and tabs, and all trailing chars.
2381
2382 If BASE, interpret STRING as a number in that base. If BASE isn't
2383 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2384 If the base used is not 10, STRING is always parsed as integer. */)
2385 (register Lisp_Object string, Lisp_Object base)
2386 {
2387 register char *p;
2388 register int b;
2389 Lisp_Object val;
2390
2391 CHECK_STRING (string);
2392
2393 if (NILP (base))
2394 b = 10;
2395 else
2396 {
2397 CHECK_NUMBER (base);
2398 b = XINT (base);
2399 if (b < 2 || b > 16)
2400 xsignal1 (Qargs_out_of_range, base);
2401 }
2402
2403 p = SSDATA (string);
2404 while (*p == ' ' || *p == '\t')
2405 p++;
2406
2407 val = string_to_number (p, b, 1);
2408 return NILP (val) ? make_number (0) : val;
2409 }
2410 \f
2411 enum arithop
2412 {
2413 Aadd,
2414 Asub,
2415 Amult,
2416 Adiv,
2417 Alogand,
2418 Alogior,
2419 Alogxor,
2420 Amax,
2421 Amin
2422 };
2423
2424 static Lisp_Object float_arith_driver (double, size_t, enum arithop,
2425 size_t, Lisp_Object *);
2426 static Lisp_Object
2427 arith_driver (enum arithop code, size_t nargs, register Lisp_Object *args)
2428 {
2429 register Lisp_Object val;
2430 register size_t argnum;
2431 register EMACS_INT accum = 0;
2432 register EMACS_INT next;
2433
2434 switch (SWITCH_ENUM_CAST (code))
2435 {
2436 case Alogior:
2437 case Alogxor:
2438 case Aadd:
2439 case Asub:
2440 accum = 0;
2441 break;
2442 case Amult:
2443 accum = 1;
2444 break;
2445 case Alogand:
2446 accum = -1;
2447 break;
2448 default:
2449 break;
2450 }
2451
2452 for (argnum = 0; argnum < nargs; argnum++)
2453 {
2454 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2455 val = args[argnum];
2456 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2457
2458 if (FLOATP (val))
2459 return float_arith_driver ((double) accum, argnum, code,
2460 nargs, args);
2461 args[argnum] = val;
2462 next = XINT (args[argnum]);
2463 switch (SWITCH_ENUM_CAST (code))
2464 {
2465 case Aadd:
2466 accum += next;
2467 break;
2468 case Asub:
2469 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2470 break;
2471 case Amult:
2472 accum *= next;
2473 break;
2474 case Adiv:
2475 if (!argnum)
2476 accum = next;
2477 else
2478 {
2479 if (next == 0)
2480 xsignal0 (Qarith_error);
2481 accum /= next;
2482 }
2483 break;
2484 case Alogand:
2485 accum &= next;
2486 break;
2487 case Alogior:
2488 accum |= next;
2489 break;
2490 case Alogxor:
2491 accum ^= next;
2492 break;
2493 case Amax:
2494 if (!argnum || next > accum)
2495 accum = next;
2496 break;
2497 case Amin:
2498 if (!argnum || next < accum)
2499 accum = next;
2500 break;
2501 }
2502 }
2503
2504 XSETINT (val, accum);
2505 return val;
2506 }
2507
2508 #undef isnan
2509 #define isnan(x) ((x) != (x))
2510
2511 static Lisp_Object
2512 float_arith_driver (double accum, register size_t argnum, enum arithop code,
2513 size_t nargs, register Lisp_Object *args)
2514 {
2515 register Lisp_Object val;
2516 double next;
2517
2518 for (; argnum < nargs; argnum++)
2519 {
2520 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2521 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2522
2523 if (FLOATP (val))
2524 {
2525 next = XFLOAT_DATA (val);
2526 }
2527 else
2528 {
2529 args[argnum] = val; /* runs into a compiler bug. */
2530 next = XINT (args[argnum]);
2531 }
2532 switch (SWITCH_ENUM_CAST (code))
2533 {
2534 case Aadd:
2535 accum += next;
2536 break;
2537 case Asub:
2538 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2539 break;
2540 case Amult:
2541 accum *= next;
2542 break;
2543 case Adiv:
2544 if (!argnum)
2545 accum = next;
2546 else
2547 {
2548 if (! IEEE_FLOATING_POINT && next == 0)
2549 xsignal0 (Qarith_error);
2550 accum /= next;
2551 }
2552 break;
2553 case Alogand:
2554 case Alogior:
2555 case Alogxor:
2556 return wrong_type_argument (Qinteger_or_marker_p, val);
2557 case Amax:
2558 if (!argnum || isnan (next) || next > accum)
2559 accum = next;
2560 break;
2561 case Amin:
2562 if (!argnum || isnan (next) || next < accum)
2563 accum = next;
2564 break;
2565 }
2566 }
2567
2568 return make_float (accum);
2569 }
2570
2571
2572 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2573 doc: /* Return sum of any number of arguments, which are numbers or markers.
2574 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2575 (size_t nargs, Lisp_Object *args)
2576 {
2577 return arith_driver (Aadd, nargs, args);
2578 }
2579
2580 DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2581 doc: /* Negate number or subtract numbers or markers and return the result.
2582 With one arg, negates it. With more than one arg,
2583 subtracts all but the first from the first.
2584 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2585 (size_t nargs, Lisp_Object *args)
2586 {
2587 return arith_driver (Asub, nargs, args);
2588 }
2589
2590 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2591 doc: /* Return product of any number of arguments, which are numbers or markers.
2592 usage: (* &rest NUMBERS-OR-MARKERS) */)
2593 (size_t nargs, Lisp_Object *args)
2594 {
2595 return arith_driver (Amult, nargs, args);
2596 }
2597
2598 DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2599 doc: /* Return first argument divided by all the remaining arguments.
2600 The arguments must be numbers or markers.
2601 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2602 (size_t nargs, Lisp_Object *args)
2603 {
2604 size_t argnum;
2605 for (argnum = 2; argnum < nargs; argnum++)
2606 if (FLOATP (args[argnum]))
2607 return float_arith_driver (0, 0, Adiv, nargs, args);
2608 return arith_driver (Adiv, nargs, args);
2609 }
2610
2611 DEFUN ("%", Frem, Srem, 2, 2, 0,
2612 doc: /* Return remainder of X divided by Y.
2613 Both must be integers or markers. */)
2614 (register Lisp_Object x, Lisp_Object y)
2615 {
2616 Lisp_Object val;
2617
2618 CHECK_NUMBER_COERCE_MARKER (x);
2619 CHECK_NUMBER_COERCE_MARKER (y);
2620
2621 if (XFASTINT (y) == 0)
2622 xsignal0 (Qarith_error);
2623
2624 XSETINT (val, XINT (x) % XINT (y));
2625 return val;
2626 }
2627
2628 #ifndef HAVE_FMOD
2629 double
2630 fmod (f1, f2)
2631 double f1, f2;
2632 {
2633 double r = f1;
2634
2635 if (f2 < 0.0)
2636 f2 = -f2;
2637
2638 /* If the magnitude of the result exceeds that of the divisor, or
2639 the sign of the result does not agree with that of the dividend,
2640 iterate with the reduced value. This does not yield a
2641 particularly accurate result, but at least it will be in the
2642 range promised by fmod. */
2643 do
2644 r -= f2 * floor (r / f2);
2645 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2646
2647 return r;
2648 }
2649 #endif /* ! HAVE_FMOD */
2650
2651 DEFUN ("mod", Fmod, Smod, 2, 2, 0,
2652 doc: /* Return X modulo Y.
2653 The result falls between zero (inclusive) and Y (exclusive).
2654 Both X and Y must be numbers or markers. */)
2655 (register Lisp_Object x, Lisp_Object y)
2656 {
2657 Lisp_Object val;
2658 EMACS_INT i1, i2;
2659
2660 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x);
2661 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y);
2662
2663 if (FLOATP (x) || FLOATP (y))
2664 return fmod_float (x, y);
2665
2666 i1 = XINT (x);
2667 i2 = XINT (y);
2668
2669 if (i2 == 0)
2670 xsignal0 (Qarith_error);
2671
2672 i1 %= i2;
2673
2674 /* If the "remainder" comes out with the wrong sign, fix it. */
2675 if (i2 < 0 ? i1 > 0 : i1 < 0)
2676 i1 += i2;
2677
2678 XSETINT (val, i1);
2679 return val;
2680 }
2681
2682 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2683 doc: /* Return largest of all the arguments (which must be numbers or markers).
2684 The value is always a number; markers are converted to numbers.
2685 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2686 (size_t nargs, Lisp_Object *args)
2687 {
2688 return arith_driver (Amax, nargs, args);
2689 }
2690
2691 DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2692 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2693 The value is always a number; markers are converted to numbers.
2694 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2695 (size_t nargs, Lisp_Object *args)
2696 {
2697 return arith_driver (Amin, nargs, args);
2698 }
2699
2700 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2701 doc: /* Return bitwise-and of all the arguments.
2702 Arguments may be integers, or markers converted to integers.
2703 usage: (logand &rest INTS-OR-MARKERS) */)
2704 (size_t nargs, Lisp_Object *args)
2705 {
2706 return arith_driver (Alogand, nargs, args);
2707 }
2708
2709 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2710 doc: /* Return bitwise-or of all the arguments.
2711 Arguments may be integers, or markers converted to integers.
2712 usage: (logior &rest INTS-OR-MARKERS) */)
2713 (size_t nargs, Lisp_Object *args)
2714 {
2715 return arith_driver (Alogior, nargs, args);
2716 }
2717
2718 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2719 doc: /* Return bitwise-exclusive-or of all the arguments.
2720 Arguments may be integers, or markers converted to integers.
2721 usage: (logxor &rest INTS-OR-MARKERS) */)
2722 (size_t nargs, Lisp_Object *args)
2723 {
2724 return arith_driver (Alogxor, nargs, args);
2725 }
2726
2727 DEFUN ("ash", Fash, Sash, 2, 2, 0,
2728 doc: /* Return VALUE with its bits shifted left by COUNT.
2729 If COUNT is negative, shifting is actually to the right.
2730 In this case, the sign bit is duplicated. */)
2731 (register Lisp_Object value, Lisp_Object count)
2732 {
2733 register Lisp_Object val;
2734
2735 CHECK_NUMBER (value);
2736 CHECK_NUMBER (count);
2737
2738 if (XINT (count) >= BITS_PER_EMACS_INT)
2739 XSETINT (val, 0);
2740 else if (XINT (count) > 0)
2741 XSETINT (val, XINT (value) << XFASTINT (count));
2742 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2743 XSETINT (val, XINT (value) < 0 ? -1 : 0);
2744 else
2745 XSETINT (val, XINT (value) >> -XINT (count));
2746 return val;
2747 }
2748
2749 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2750 doc: /* Return VALUE with its bits shifted left by COUNT.
2751 If COUNT is negative, shifting is actually to the right.
2752 In this case, zeros are shifted in on the left. */)
2753 (register Lisp_Object value, Lisp_Object count)
2754 {
2755 register Lisp_Object val;
2756
2757 CHECK_NUMBER (value);
2758 CHECK_NUMBER (count);
2759
2760 if (XINT (count) >= BITS_PER_EMACS_INT)
2761 XSETINT (val, 0);
2762 else if (XINT (count) > 0)
2763 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
2764 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2765 XSETINT (val, 0);
2766 else
2767 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
2768 return val;
2769 }
2770
2771 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2772 doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2773 Markers are converted to integers. */)
2774 (register Lisp_Object number)
2775 {
2776 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2777
2778 if (FLOATP (number))
2779 return (make_float (1.0 + XFLOAT_DATA (number)));
2780
2781 XSETINT (number, XINT (number) + 1);
2782 return number;
2783 }
2784
2785 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2786 doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2787 Markers are converted to integers. */)
2788 (register Lisp_Object number)
2789 {
2790 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2791
2792 if (FLOATP (number))
2793 return (make_float (-1.0 + XFLOAT_DATA (number)));
2794
2795 XSETINT (number, XINT (number) - 1);
2796 return number;
2797 }
2798
2799 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2800 doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2801 (register Lisp_Object number)
2802 {
2803 CHECK_NUMBER (number);
2804 XSETINT (number, ~XINT (number));
2805 return number;
2806 }
2807
2808 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2809 doc: /* Return the byteorder for the machine.
2810 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2811 lowercase l) for small endian machines. */)
2812 (void)
2813 {
2814 unsigned i = 0x04030201;
2815 int order = *(char *)&i == 1 ? 108 : 66;
2816
2817 return make_number (order);
2818 }
2819
2820
2821 \f
2822 void
2823 syms_of_data (void)
2824 {
2825 Lisp_Object error_tail, arith_tail;
2826
2827 Qquote = intern_c_string ("quote");
2828 Qlambda = intern_c_string ("lambda");
2829 Qsubr = intern_c_string ("subr");
2830 Qerror_conditions = intern_c_string ("error-conditions");
2831 Qerror_message = intern_c_string ("error-message");
2832 Qtop_level = intern_c_string ("top-level");
2833
2834 Qerror = intern_c_string ("error");
2835 Qquit = intern_c_string ("quit");
2836 Qwrong_type_argument = intern_c_string ("wrong-type-argument");
2837 Qargs_out_of_range = intern_c_string ("args-out-of-range");
2838 Qvoid_function = intern_c_string ("void-function");
2839 Qcyclic_function_indirection = intern_c_string ("cyclic-function-indirection");
2840 Qcyclic_variable_indirection = intern_c_string ("cyclic-variable-indirection");
2841 Qvoid_variable = intern_c_string ("void-variable");
2842 Qsetting_constant = intern_c_string ("setting-constant");
2843 Qinvalid_read_syntax = intern_c_string ("invalid-read-syntax");
2844
2845 Qinvalid_function = intern_c_string ("invalid-function");
2846 Qwrong_number_of_arguments = intern_c_string ("wrong-number-of-arguments");
2847 Qno_catch = intern_c_string ("no-catch");
2848 Qend_of_file = intern_c_string ("end-of-file");
2849 Qarith_error = intern_c_string ("arith-error");
2850 Qbeginning_of_buffer = intern_c_string ("beginning-of-buffer");
2851 Qend_of_buffer = intern_c_string ("end-of-buffer");
2852 Qbuffer_read_only = intern_c_string ("buffer-read-only");
2853 Qtext_read_only = intern_c_string ("text-read-only");
2854 Qmark_inactive = intern_c_string ("mark-inactive");
2855
2856 Qlistp = intern_c_string ("listp");
2857 Qconsp = intern_c_string ("consp");
2858 Qsymbolp = intern_c_string ("symbolp");
2859 Qkeywordp = intern_c_string ("keywordp");
2860 Qintegerp = intern_c_string ("integerp");
2861 Qnatnump = intern_c_string ("natnump");
2862 Qwholenump = intern_c_string ("wholenump");
2863 Qstringp = intern_c_string ("stringp");
2864 Qarrayp = intern_c_string ("arrayp");
2865 Qsequencep = intern_c_string ("sequencep");
2866 Qbufferp = intern_c_string ("bufferp");
2867 Qvectorp = intern_c_string ("vectorp");
2868 Qchar_or_string_p = intern_c_string ("char-or-string-p");
2869 Qmarkerp = intern_c_string ("markerp");
2870 Qbuffer_or_string_p = intern_c_string ("buffer-or-string-p");
2871 Qinteger_or_marker_p = intern_c_string ("integer-or-marker-p");
2872 Qboundp = intern_c_string ("boundp");
2873 Qfboundp = intern_c_string ("fboundp");
2874
2875 Qfloatp = intern_c_string ("floatp");
2876 Qnumberp = intern_c_string ("numberp");
2877 Qnumber_or_marker_p = intern_c_string ("number-or-marker-p");
2878
2879 Qchar_table_p = intern_c_string ("char-table-p");
2880 Qvector_or_char_table_p = intern_c_string ("vector-or-char-table-p");
2881
2882 Qsubrp = intern_c_string ("subrp");
2883 Qunevalled = intern_c_string ("unevalled");
2884 Qmany = intern_c_string ("many");
2885
2886 Qcdr = intern_c_string ("cdr");
2887
2888 /* Handle automatic advice activation */
2889 Qad_advice_info = intern_c_string ("ad-advice-info");
2890 Qad_activate_internal = intern_c_string ("ad-activate-internal");
2891
2892 error_tail = pure_cons (Qerror, Qnil);
2893
2894 /* ERROR is used as a signaler for random errors for which nothing else is right */
2895
2896 Fput (Qerror, Qerror_conditions,
2897 error_tail);
2898 Fput (Qerror, Qerror_message,
2899 make_pure_c_string ("error"));
2900
2901 Fput (Qquit, Qerror_conditions,
2902 pure_cons (Qquit, Qnil));
2903 Fput (Qquit, Qerror_message,
2904 make_pure_c_string ("Quit"));
2905
2906 Fput (Qwrong_type_argument, Qerror_conditions,
2907 pure_cons (Qwrong_type_argument, error_tail));
2908 Fput (Qwrong_type_argument, Qerror_message,
2909 make_pure_c_string ("Wrong type argument"));
2910
2911 Fput (Qargs_out_of_range, Qerror_conditions,
2912 pure_cons (Qargs_out_of_range, error_tail));
2913 Fput (Qargs_out_of_range, Qerror_message,
2914 make_pure_c_string ("Args out of range"));
2915
2916 Fput (Qvoid_function, Qerror_conditions,
2917 pure_cons (Qvoid_function, error_tail));
2918 Fput (Qvoid_function, Qerror_message,
2919 make_pure_c_string ("Symbol's function definition is void"));
2920
2921 Fput (Qcyclic_function_indirection, Qerror_conditions,
2922 pure_cons (Qcyclic_function_indirection, error_tail));
2923 Fput (Qcyclic_function_indirection, Qerror_message,
2924 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
2925
2926 Fput (Qcyclic_variable_indirection, Qerror_conditions,
2927 pure_cons (Qcyclic_variable_indirection, error_tail));
2928 Fput (Qcyclic_variable_indirection, Qerror_message,
2929 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
2930
2931 Qcircular_list = intern_c_string ("circular-list");
2932 staticpro (&Qcircular_list);
2933 Fput (Qcircular_list, Qerror_conditions,
2934 pure_cons (Qcircular_list, error_tail));
2935 Fput (Qcircular_list, Qerror_message,
2936 make_pure_c_string ("List contains a loop"));
2937
2938 Fput (Qvoid_variable, Qerror_conditions,
2939 pure_cons (Qvoid_variable, error_tail));
2940 Fput (Qvoid_variable, Qerror_message,
2941 make_pure_c_string ("Symbol's value as variable is void"));
2942
2943 Fput (Qsetting_constant, Qerror_conditions,
2944 pure_cons (Qsetting_constant, error_tail));
2945 Fput (Qsetting_constant, Qerror_message,
2946 make_pure_c_string ("Attempt to set a constant symbol"));
2947
2948 Fput (Qinvalid_read_syntax, Qerror_conditions,
2949 pure_cons (Qinvalid_read_syntax, error_tail));
2950 Fput (Qinvalid_read_syntax, Qerror_message,
2951 make_pure_c_string ("Invalid read syntax"));
2952
2953 Fput (Qinvalid_function, Qerror_conditions,
2954 pure_cons (Qinvalid_function, error_tail));
2955 Fput (Qinvalid_function, Qerror_message,
2956 make_pure_c_string ("Invalid function"));
2957
2958 Fput (Qwrong_number_of_arguments, Qerror_conditions,
2959 pure_cons (Qwrong_number_of_arguments, error_tail));
2960 Fput (Qwrong_number_of_arguments, Qerror_message,
2961 make_pure_c_string ("Wrong number of arguments"));
2962
2963 Fput (Qno_catch, Qerror_conditions,
2964 pure_cons (Qno_catch, error_tail));
2965 Fput (Qno_catch, Qerror_message,
2966 make_pure_c_string ("No catch for tag"));
2967
2968 Fput (Qend_of_file, Qerror_conditions,
2969 pure_cons (Qend_of_file, error_tail));
2970 Fput (Qend_of_file, Qerror_message,
2971 make_pure_c_string ("End of file during parsing"));
2972
2973 arith_tail = pure_cons (Qarith_error, error_tail);
2974 Fput (Qarith_error, Qerror_conditions,
2975 arith_tail);
2976 Fput (Qarith_error, Qerror_message,
2977 make_pure_c_string ("Arithmetic error"));
2978
2979 Fput (Qbeginning_of_buffer, Qerror_conditions,
2980 pure_cons (Qbeginning_of_buffer, error_tail));
2981 Fput (Qbeginning_of_buffer, Qerror_message,
2982 make_pure_c_string ("Beginning of buffer"));
2983
2984 Fput (Qend_of_buffer, Qerror_conditions,
2985 pure_cons (Qend_of_buffer, error_tail));
2986 Fput (Qend_of_buffer, Qerror_message,
2987 make_pure_c_string ("End of buffer"));
2988
2989 Fput (Qbuffer_read_only, Qerror_conditions,
2990 pure_cons (Qbuffer_read_only, error_tail));
2991 Fput (Qbuffer_read_only, Qerror_message,
2992 make_pure_c_string ("Buffer is read-only"));
2993
2994 Fput (Qtext_read_only, Qerror_conditions,
2995 pure_cons (Qtext_read_only, error_tail));
2996 Fput (Qtext_read_only, Qerror_message,
2997 make_pure_c_string ("Text is read-only"));
2998
2999 Qrange_error = intern_c_string ("range-error");
3000 Qdomain_error = intern_c_string ("domain-error");
3001 Qsingularity_error = intern_c_string ("singularity-error");
3002 Qoverflow_error = intern_c_string ("overflow-error");
3003 Qunderflow_error = intern_c_string ("underflow-error");
3004
3005 Fput (Qdomain_error, Qerror_conditions,
3006 pure_cons (Qdomain_error, arith_tail));
3007 Fput (Qdomain_error, Qerror_message,
3008 make_pure_c_string ("Arithmetic domain error"));
3009
3010 Fput (Qrange_error, Qerror_conditions,
3011 pure_cons (Qrange_error, arith_tail));
3012 Fput (Qrange_error, Qerror_message,
3013 make_pure_c_string ("Arithmetic range error"));
3014
3015 Fput (Qsingularity_error, Qerror_conditions,
3016 pure_cons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3017 Fput (Qsingularity_error, Qerror_message,
3018 make_pure_c_string ("Arithmetic singularity error"));
3019
3020 Fput (Qoverflow_error, Qerror_conditions,
3021 pure_cons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3022 Fput (Qoverflow_error, Qerror_message,
3023 make_pure_c_string ("Arithmetic overflow error"));
3024
3025 Fput (Qunderflow_error, Qerror_conditions,
3026 pure_cons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3027 Fput (Qunderflow_error, Qerror_message,
3028 make_pure_c_string ("Arithmetic underflow error"));
3029
3030 staticpro (&Qrange_error);
3031 staticpro (&Qdomain_error);
3032 staticpro (&Qsingularity_error);
3033 staticpro (&Qoverflow_error);
3034 staticpro (&Qunderflow_error);
3035
3036 staticpro (&Qnil);
3037 staticpro (&Qt);
3038 staticpro (&Qquote);
3039 staticpro (&Qlambda);
3040 staticpro (&Qsubr);
3041 staticpro (&Qunbound);
3042 staticpro (&Qerror_conditions);
3043 staticpro (&Qerror_message);
3044 staticpro (&Qtop_level);
3045
3046 staticpro (&Qerror);
3047 staticpro (&Qquit);
3048 staticpro (&Qwrong_type_argument);
3049 staticpro (&Qargs_out_of_range);
3050 staticpro (&Qvoid_function);
3051 staticpro (&Qcyclic_function_indirection);
3052 staticpro (&Qcyclic_variable_indirection);
3053 staticpro (&Qvoid_variable);
3054 staticpro (&Qsetting_constant);
3055 staticpro (&Qinvalid_read_syntax);
3056 staticpro (&Qwrong_number_of_arguments);
3057 staticpro (&Qinvalid_function);
3058 staticpro (&Qno_catch);
3059 staticpro (&Qend_of_file);
3060 staticpro (&Qarith_error);
3061 staticpro (&Qbeginning_of_buffer);
3062 staticpro (&Qend_of_buffer);
3063 staticpro (&Qbuffer_read_only);
3064 staticpro (&Qtext_read_only);
3065 staticpro (&Qmark_inactive);
3066
3067 staticpro (&Qlistp);
3068 staticpro (&Qconsp);
3069 staticpro (&Qsymbolp);
3070 staticpro (&Qkeywordp);
3071 staticpro (&Qintegerp);
3072 staticpro (&Qnatnump);
3073 staticpro (&Qwholenump);
3074 staticpro (&Qstringp);
3075 staticpro (&Qarrayp);
3076 staticpro (&Qsequencep);
3077 staticpro (&Qbufferp);
3078 staticpro (&Qvectorp);
3079 staticpro (&Qchar_or_string_p);
3080 staticpro (&Qmarkerp);
3081 staticpro (&Qbuffer_or_string_p);
3082 staticpro (&Qinteger_or_marker_p);
3083 staticpro (&Qfloatp);
3084 staticpro (&Qnumberp);
3085 staticpro (&Qnumber_or_marker_p);
3086 staticpro (&Qchar_table_p);
3087 staticpro (&Qvector_or_char_table_p);
3088 staticpro (&Qsubrp);
3089 staticpro (&Qmany);
3090 staticpro (&Qunevalled);
3091
3092 staticpro (&Qboundp);
3093 staticpro (&Qfboundp);
3094 staticpro (&Qcdr);
3095 staticpro (&Qad_advice_info);
3096 staticpro (&Qad_activate_internal);
3097
3098 /* Types that type-of returns. */
3099 Qinteger = intern_c_string ("integer");
3100 Qsymbol = intern_c_string ("symbol");
3101 Qstring = intern_c_string ("string");
3102 Qcons = intern_c_string ("cons");
3103 Qmarker = intern_c_string ("marker");
3104 Qoverlay = intern_c_string ("overlay");
3105 Qfloat = intern_c_string ("float");
3106 Qwindow_configuration = intern_c_string ("window-configuration");
3107 Qprocess = intern_c_string ("process");
3108 Qwindow = intern_c_string ("window");
3109 /* Qsubr = intern_c_string ("subr"); */
3110 Qcompiled_function = intern_c_string ("compiled-function");
3111 Qbuffer = intern_c_string ("buffer");
3112 Qframe = intern_c_string ("frame");
3113 Qvector = intern_c_string ("vector");
3114 Qchar_table = intern_c_string ("char-table");
3115 Qbool_vector = intern_c_string ("bool-vector");
3116 Qhash_table = intern_c_string ("hash-table");
3117
3118 DEFSYM (Qfont_spec, "font-spec");
3119 DEFSYM (Qfont_entity, "font-entity");
3120 DEFSYM (Qfont_object, "font-object");
3121
3122 DEFSYM (Qinteractive_form, "interactive-form");
3123
3124 staticpro (&Qinteger);
3125 staticpro (&Qsymbol);
3126 staticpro (&Qstring);
3127 staticpro (&Qcons);
3128 staticpro (&Qmarker);
3129 staticpro (&Qoverlay);
3130 staticpro (&Qfloat);
3131 staticpro (&Qwindow_configuration);
3132 staticpro (&Qprocess);
3133 staticpro (&Qwindow);
3134 /* staticpro (&Qsubr); */
3135 staticpro (&Qcompiled_function);
3136 staticpro (&Qbuffer);
3137 staticpro (&Qframe);
3138 staticpro (&Qvector);
3139 staticpro (&Qchar_table);
3140 staticpro (&Qbool_vector);
3141 staticpro (&Qhash_table);
3142
3143 defsubr (&Sindirect_variable);
3144 defsubr (&Sinteractive_form);
3145 defsubr (&Seq);
3146 defsubr (&Snull);
3147 defsubr (&Stype_of);
3148 defsubr (&Slistp);
3149 defsubr (&Snlistp);
3150 defsubr (&Sconsp);
3151 defsubr (&Satom);
3152 defsubr (&Sintegerp);
3153 defsubr (&Sinteger_or_marker_p);
3154 defsubr (&Snumberp);
3155 defsubr (&Snumber_or_marker_p);
3156 defsubr (&Sfloatp);
3157 defsubr (&Snatnump);
3158 defsubr (&Ssymbolp);
3159 defsubr (&Skeywordp);
3160 defsubr (&Sstringp);
3161 defsubr (&Smultibyte_string_p);
3162 defsubr (&Svectorp);
3163 defsubr (&Schar_table_p);
3164 defsubr (&Svector_or_char_table_p);
3165 defsubr (&Sbool_vector_p);
3166 defsubr (&Sarrayp);
3167 defsubr (&Ssequencep);
3168 defsubr (&Sbufferp);
3169 defsubr (&Smarkerp);
3170 defsubr (&Ssubrp);
3171 defsubr (&Sbyte_code_function_p);
3172 defsubr (&Schar_or_string_p);
3173 defsubr (&Scar);
3174 defsubr (&Scdr);
3175 defsubr (&Scar_safe);
3176 defsubr (&Scdr_safe);
3177 defsubr (&Ssetcar);
3178 defsubr (&Ssetcdr);
3179 defsubr (&Ssymbol_function);
3180 defsubr (&Sindirect_function);
3181 defsubr (&Ssymbol_plist);
3182 defsubr (&Ssymbol_name);
3183 defsubr (&Smakunbound);
3184 defsubr (&Sfmakunbound);
3185 defsubr (&Sboundp);
3186 defsubr (&Sfboundp);
3187 defsubr (&Sfset);
3188 defsubr (&Sdefalias);
3189 defsubr (&Ssetplist);
3190 defsubr (&Ssymbol_value);
3191 defsubr (&Sset);
3192 defsubr (&Sdefault_boundp);
3193 defsubr (&Sdefault_value);
3194 defsubr (&Sset_default);
3195 defsubr (&Ssetq_default);
3196 defsubr (&Smake_variable_buffer_local);
3197 defsubr (&Smake_local_variable);
3198 defsubr (&Skill_local_variable);
3199 defsubr (&Smake_variable_frame_local);
3200 defsubr (&Slocal_variable_p);
3201 defsubr (&Slocal_variable_if_set_p);
3202 defsubr (&Svariable_binding_locus);
3203 #if 0 /* XXX Remove this. --lorentey */
3204 defsubr (&Sterminal_local_value);
3205 defsubr (&Sset_terminal_local_value);
3206 #endif
3207 defsubr (&Saref);
3208 defsubr (&Saset);
3209 defsubr (&Snumber_to_string);
3210 defsubr (&Sstring_to_number);
3211 defsubr (&Seqlsign);
3212 defsubr (&Slss);
3213 defsubr (&Sgtr);
3214 defsubr (&Sleq);
3215 defsubr (&Sgeq);
3216 defsubr (&Sneq);
3217 defsubr (&Szerop);
3218 defsubr (&Splus);
3219 defsubr (&Sminus);
3220 defsubr (&Stimes);
3221 defsubr (&Squo);
3222 defsubr (&Srem);
3223 defsubr (&Smod);
3224 defsubr (&Smax);
3225 defsubr (&Smin);
3226 defsubr (&Slogand);
3227 defsubr (&Slogior);
3228 defsubr (&Slogxor);
3229 defsubr (&Slsh);
3230 defsubr (&Sash);
3231 defsubr (&Sadd1);
3232 defsubr (&Ssub1);
3233 defsubr (&Slognot);
3234 defsubr (&Sbyteorder);
3235 defsubr (&Ssubr_arity);
3236 defsubr (&Ssubr_name);
3237
3238 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3239
3240 DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum,
3241 doc: /* The largest value that is representable in a Lisp integer. */);
3242 Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM);
3243 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1;
3244
3245 DEFVAR_LISP ("most-negative-fixnum", Vmost_negative_fixnum,
3246 doc: /* The smallest value that is representable in a Lisp integer. */);
3247 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3248 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3249 }
3250
3251 #ifndef FORWARD_SIGNAL_TO_MAIN_THREAD
3252 static void arith_error (int) NO_RETURN;
3253 #endif
3254
3255 static void
3256 arith_error (int signo)
3257 {
3258 sigsetmask (SIGEMPTYMASK);
3259
3260 SIGNAL_THREAD_CHECK (signo);
3261 xsignal0 (Qarith_error);
3262 }
3263
3264 void
3265 init_data (void)
3266 {
3267 /* Don't do this if just dumping out.
3268 We don't want to call `signal' in this case
3269 so that we don't have trouble with dumping
3270 signal-delivering routines in an inconsistent state. */
3271 #ifndef CANNOT_DUMP
3272 if (!initialized)
3273 return;
3274 #endif /* CANNOT_DUMP */
3275 signal (SIGFPE, arith_error);
3276
3277 #ifdef uts
3278 signal (SIGEMT, arith_error);
3279 #endif /* uts */
3280 }