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