Mercurial > emacs
annotate src/data.c @ 957:2619b7a9c11e
entered into RCS
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 12 Aug 1992 12:50:10 +0000 |
parents | 62dd28940dc6 |
children | 65f15f1961d8 |
rev | line source |
---|---|
298 | 1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. |
591 | 2 Copyright (C) 1985, 1986, 1988, 1992 Free Software Foundation, Inc. |
298 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include <signal.h> | |
22 | |
23 #include "config.h" | |
24 #include "lisp.h" | |
336 | 25 #include "puresize.h" |
298 | 26 |
27 #ifndef standalone | |
28 #include "buffer.h" | |
29 #endif | |
30 | |
552 | 31 #include "syssignal.h" |
348 | 32 |
298 | 33 #ifdef LISP_FLOAT_TYPE |
34 #include <math.h> | |
35 #endif /* LISP_FLOAT_TYPE */ | |
36 | |
37 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound; | |
38 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; | |
39 Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range; | |
648 | 40 Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection; |
298 | 41 Lisp_Object Qsetting_constant, Qinvalid_read_syntax; |
42 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; | |
43 Lisp_Object Qend_of_file, Qarith_error; | |
44 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; | |
45 Lisp_Object Qintegerp, Qnatnump, Qsymbolp, Qlistp, Qconsp; | |
46 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; | |
47 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; | |
48 Lisp_Object Qboundp, Qfboundp; | |
49 Lisp_Object Qcdr; | |
50 | |
51 #ifdef LISP_FLOAT_TYPE | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
52 Lisp_Object Qfloatp; |
298 | 53 Lisp_Object Qnumberp, Qnumber_or_marker_p; |
54 #endif | |
55 | |
56 static Lisp_Object swap_in_symval_forwarding (); | |
57 | |
58 Lisp_Object | |
59 wrong_type_argument (predicate, value) | |
60 register Lisp_Object predicate, value; | |
61 { | |
62 register Lisp_Object tem; | |
63 do | |
64 { | |
65 if (!EQ (Vmocklisp_arguments, Qt)) | |
66 { | |
67 if (XTYPE (value) == Lisp_String && | |
68 (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p))) | |
69 return Fstring_to_int (value, Qt); | |
70 if (XTYPE (value) == Lisp_Int && EQ (predicate, Qstringp)) | |
71 return Fint_to_string (value); | |
72 } | |
73 value = Fsignal (Qwrong_type_argument, Fcons (predicate, Fcons (value, Qnil))); | |
74 tem = call1 (predicate, value); | |
75 } | |
490 | 76 while (NILP (tem)); |
298 | 77 return value; |
78 } | |
79 | |
80 pure_write_error () | |
81 { | |
82 error ("Attempt to modify read-only object"); | |
83 } | |
84 | |
85 void | |
86 args_out_of_range (a1, a2) | |
87 Lisp_Object a1, a2; | |
88 { | |
89 while (1) | |
90 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Qnil))); | |
91 } | |
92 | |
93 void | |
94 args_out_of_range_3 (a1, a2, a3) | |
95 Lisp_Object a1, a2, a3; | |
96 { | |
97 while (1) | |
98 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Fcons (a3, Qnil)))); | |
99 } | |
100 | |
101 Lisp_Object | |
102 make_number (num) | |
103 int num; | |
104 { | |
105 register Lisp_Object val; | |
106 XSET (val, Lisp_Int, num); | |
107 return val; | |
108 } | |
109 | |
110 /* On some machines, XINT needs a temporary location. | |
111 Here it is, in case it is needed. */ | |
112 | |
113 int sign_extend_temp; | |
114 | |
115 /* On a few machines, XINT can only be done by calling this. */ | |
116 | |
117 int | |
118 sign_extend_lisp_int (num) | |
119 int num; | |
120 { | |
121 if (num & (1 << (VALBITS - 1))) | |
122 return num | ((-1) << VALBITS); | |
123 else | |
124 return num & ((1 << VALBITS) - 1); | |
125 } | |
126 | |
127 /* Data type predicates */ | |
128 | |
129 DEFUN ("eq", Feq, Seq, 2, 2, 0, | |
130 "T if the two args are the same Lisp object.") | |
131 (obj1, obj2) | |
132 Lisp_Object obj1, obj2; | |
133 { | |
134 if (EQ (obj1, obj2)) | |
135 return Qt; | |
136 return Qnil; | |
137 } | |
138 | |
139 DEFUN ("null", Fnull, Snull, 1, 1, 0, "T if OBJECT is nil.") | |
140 (obj) | |
141 Lisp_Object obj; | |
142 { | |
490 | 143 if (NILP (obj)) |
298 | 144 return Qt; |
145 return Qnil; | |
146 } | |
147 | |
148 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.") | |
149 (obj) | |
150 Lisp_Object obj; | |
151 { | |
152 if (XTYPE (obj) == Lisp_Cons) | |
153 return Qt; | |
154 return Qnil; | |
155 } | |
156 | |
157 DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.") | |
158 (obj) | |
159 Lisp_Object obj; | |
160 { | |
161 if (XTYPE (obj) == Lisp_Cons) | |
162 return Qnil; | |
163 return Qt; | |
164 } | |
165 | |
166 DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list. This includes nil.") | |
167 (obj) | |
168 Lisp_Object obj; | |
169 { | |
490 | 170 if (XTYPE (obj) == Lisp_Cons || NILP (obj)) |
298 | 171 return Qt; |
172 return Qnil; | |
173 } | |
174 | |
175 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.") | |
176 (obj) | |
177 Lisp_Object obj; | |
178 { | |
490 | 179 if (XTYPE (obj) == Lisp_Cons || NILP (obj)) |
298 | 180 return Qnil; |
181 return Qt; | |
182 } | |
183 | |
184 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.") | |
185 (obj) | |
186 Lisp_Object obj; | |
187 { | |
188 if (XTYPE (obj) == Lisp_Symbol) | |
189 return Qt; | |
190 return Qnil; | |
191 } | |
192 | |
193 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.") | |
194 (obj) | |
195 Lisp_Object obj; | |
196 { | |
197 if (XTYPE (obj) == Lisp_Vector) | |
198 return Qt; | |
199 return Qnil; | |
200 } | |
201 | |
202 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.") | |
203 (obj) | |
204 Lisp_Object obj; | |
205 { | |
206 if (XTYPE (obj) == Lisp_String) | |
207 return Qt; | |
208 return Qnil; | |
209 } | |
210 | |
211 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or vector).") | |
212 (obj) | |
213 Lisp_Object obj; | |
214 { | |
215 if (XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String) | |
216 return Qt; | |
217 return Qnil; | |
218 } | |
219 | |
220 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0, | |
221 "T if OBJECT is a sequence (list or array).") | |
222 (obj) | |
223 register Lisp_Object obj; | |
224 { | |
490 | 225 if (CONSP (obj) || NILP (obj) || |
298 | 226 XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String) |
227 return Qt; | |
228 return Qnil; | |
229 } | |
230 | |
231 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.") | |
232 (obj) | |
233 Lisp_Object obj; | |
234 { | |
235 if (XTYPE (obj) == Lisp_Buffer) | |
236 return Qt; | |
237 return Qnil; | |
238 } | |
239 | |
240 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor pointer).") | |
241 (obj) | |
242 Lisp_Object obj; | |
243 { | |
244 if (XTYPE (obj) == Lisp_Marker) | |
245 return Qt; | |
246 return Qnil; | |
247 } | |
248 | |
249 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.") | |
250 (obj) | |
251 Lisp_Object obj; | |
252 { | |
253 if (XTYPE (obj) == Lisp_Subr) | |
254 return Qt; | |
255 return Qnil; | |
256 } | |
257 | |
258 DEFUN ("compiled-function-p", Fcompiled_function_p, Scompiled_function_p, | |
259 1, 1, 0, "T if OBJECT is a compiled function object.") | |
260 (obj) | |
261 Lisp_Object obj; | |
262 { | |
263 if (XTYPE (obj) == Lisp_Compiled) | |
264 return Qt; | |
265 return Qnil; | |
266 } | |
267 | |
268 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0, "T if OBJECT is a character (a number) or a string.") | |
269 (obj) | |
270 register Lisp_Object obj; | |
271 { | |
272 if (XTYPE (obj) == Lisp_Int || XTYPE (obj) == Lisp_String) | |
273 return Qt; | |
274 return Qnil; | |
275 } | |
276 | |
277 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is a number.") | |
278 (obj) | |
279 Lisp_Object obj; | |
280 { | |
281 if (XTYPE (obj) == Lisp_Int) | |
282 return Qt; | |
283 return Qnil; | |
284 } | |
285 | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
286 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
287 "T if OBJECT is an integer or a marker (editor pointer).") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
288 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
289 register Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
290 { |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
291 if (XTYPE (obj) == Lisp_Marker || XTYPE (obj) == Lisp_Int) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
292 return Qt; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
293 return Qnil; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
294 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
295 |
298 | 296 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0, "T if OBJECT is a nonnegative number.") |
297 (obj) | |
298 Lisp_Object obj; | |
299 { | |
300 if (XTYPE (obj) == Lisp_Int && XINT (obj) >= 0) | |
301 return Qt; | |
302 return Qnil; | |
303 } | |
304 | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
305 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
306 "T if OBJECT is a number (floating point or integer).") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
307 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
308 Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
309 { |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
310 if (0 |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
311 #ifdef LISP_FLOAT_TYPE |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
312 || XTYPE (obj) == Lisp_Float |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
313 #endif |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
314 || XTYPE (obj) == Lisp_Int) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
315 return Qt; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
316 return Qnil; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
317 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
318 |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
319 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
320 Snumber_or_marker_p, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
321 "T if OBJECT is a number or a marker.") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
322 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
323 Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
324 { |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
325 if (XTYPE (obj) == Lisp_Int |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
326 #ifdef LISP_FLOAT_TYPE |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
327 || XTYPE (obj) == Lisp_Float |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
328 #endif |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
329 || XTYPE (obj) == Lisp_Marker) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
330 return Qt; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
331 return Qnil; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
332 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
333 |
298 | 334 #ifdef LISP_FLOAT_TYPE |
335 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0, | |
336 "T if OBJECT is a floating point number.") | |
337 (obj) | |
338 Lisp_Object obj; | |
339 { | |
340 if (XTYPE (obj) == Lisp_Float) | |
341 return Qt; | |
342 return Qnil; | |
343 } | |
344 #endif /* LISP_FLOAT_TYPE */ | |
345 | |
346 /* Extract and set components of lists */ | |
347 | |
348 DEFUN ("car", Fcar, Scar, 1, 1, 0, | |
349 "Return the car of CONSCELL. If arg is nil, return nil.\n\ | |
350 Error if arg is not nil and not a cons cell. See also `car-safe'.") | |
351 (list) | |
352 register Lisp_Object list; | |
353 { | |
354 while (1) | |
355 { | |
356 if (XTYPE (list) == Lisp_Cons) | |
357 return XCONS (list)->car; | |
358 else if (EQ (list, Qnil)) | |
359 return Qnil; | |
360 else | |
361 list = wrong_type_argument (Qlistp, list); | |
362 } | |
363 } | |
364 | |
365 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0, | |
366 "Return the car of OBJECT if it is a cons cell, or else nil.") | |
367 (object) | |
368 Lisp_Object object; | |
369 { | |
370 if (XTYPE (object) == Lisp_Cons) | |
371 return XCONS (object)->car; | |
372 else | |
373 return Qnil; | |
374 } | |
375 | |
376 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0, | |
377 "Return the cdr of CONSCELL. If arg is nil, return nil.\n\ | |
378 Error if arg is not nil and not a cons cell. See also `cdr-safe'.") | |
379 | |
380 (list) | |
381 register Lisp_Object list; | |
382 { | |
383 while (1) | |
384 { | |
385 if (XTYPE (list) == Lisp_Cons) | |
386 return XCONS (list)->cdr; | |
387 else if (EQ (list, Qnil)) | |
388 return Qnil; | |
389 else | |
390 list = wrong_type_argument (Qlistp, list); | |
391 } | |
392 } | |
393 | |
394 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0, | |
395 "Return the cdr of OBJECT if it is a cons cell, or else nil.") | |
396 (object) | |
397 Lisp_Object object; | |
398 { | |
399 if (XTYPE (object) == Lisp_Cons) | |
400 return XCONS (object)->cdr; | |
401 else | |
402 return Qnil; | |
403 } | |
404 | |
405 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0, | |
406 "Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.") | |
407 (cell, newcar) | |
408 register Lisp_Object cell, newcar; | |
409 { | |
410 if (XTYPE (cell) != Lisp_Cons) | |
411 cell = wrong_type_argument (Qconsp, cell); | |
412 | |
413 CHECK_IMPURE (cell); | |
414 XCONS (cell)->car = newcar; | |
415 return newcar; | |
416 } | |
417 | |
418 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0, | |
419 "Set the cdr of CONSCELL to be NEWCDR. Returns NEWCDR.") | |
420 (cell, newcdr) | |
421 register Lisp_Object cell, newcdr; | |
422 { | |
423 if (XTYPE (cell) != Lisp_Cons) | |
424 cell = wrong_type_argument (Qconsp, cell); | |
425 | |
426 CHECK_IMPURE (cell); | |
427 XCONS (cell)->cdr = newcdr; | |
428 return newcdr; | |
429 } | |
430 | |
431 /* Extract and set components of symbols */ | |
432 | |
433 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.") | |
434 (sym) | |
435 register Lisp_Object sym; | |
436 { | |
437 Lisp_Object valcontents; | |
438 CHECK_SYMBOL (sym, 0); | |
439 | |
440 valcontents = XSYMBOL (sym)->value; | |
441 | |
442 #ifdef SWITCH_ENUM_BUG | |
443 switch ((int) XTYPE (valcontents)) | |
444 #else | |
445 switch (XTYPE (valcontents)) | |
446 #endif | |
447 { | |
448 case Lisp_Buffer_Local_Value: | |
449 case Lisp_Some_Buffer_Local_Value: | |
450 valcontents = swap_in_symval_forwarding (sym, valcontents); | |
451 } | |
452 | |
453 return (XTYPE (valcontents) == Lisp_Void || EQ (valcontents, Qunbound) | |
454 ? Qnil : Qt); | |
455 } | |
456 | |
457 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "T if SYMBOL's function definition is not void.") | |
458 (sym) | |
459 register Lisp_Object sym; | |
460 { | |
461 CHECK_SYMBOL (sym, 0); | |
462 return (XTYPE (XSYMBOL (sym)->function) == Lisp_Void | |
463 || EQ (XSYMBOL (sym)->function, Qunbound)) | |
464 ? Qnil : Qt; | |
465 } | |
466 | |
467 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, "Make SYMBOL's value be void.") | |
468 (sym) | |
469 register Lisp_Object sym; | |
470 { | |
471 CHECK_SYMBOL (sym, 0); | |
490 | 472 if (NILP (sym) || EQ (sym, Qt)) |
298 | 473 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
474 Fset (sym, Qunbound); | |
475 return sym; | |
476 } | |
477 | |
478 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, "Make SYMBOL's function definition be void.") | |
479 (sym) | |
480 register Lisp_Object sym; | |
481 { | |
482 CHECK_SYMBOL (sym, 0); | |
483 XSYMBOL (sym)->function = Qunbound; | |
484 return sym; | |
485 } | |
486 | |
487 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0, | |
488 "Return SYMBOL's function definition. Error if that is void.") | |
648 | 489 (symbol) |
490 register Lisp_Object symbol; | |
298 | 491 { |
648 | 492 CHECK_SYMBOL (symbol, 0); |
493 if (EQ (XSYMBOL (symbol)->function, Qunbound)) | |
494 return Fsignal (Qvoid_function, Fcons (symbol, Qnil)); | |
495 return XSYMBOL (symbol)->function; | |
298 | 496 } |
497 | |
498 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, "Return SYMBOL's property list.") | |
499 (sym) | |
500 register Lisp_Object sym; | |
501 { | |
502 CHECK_SYMBOL (sym, 0); | |
503 return XSYMBOL (sym)->plist; | |
504 } | |
505 | |
506 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, "Return SYMBOL's name, a string.") | |
507 (sym) | |
508 register Lisp_Object sym; | |
509 { | |
510 register Lisp_Object name; | |
511 | |
512 CHECK_SYMBOL (sym, 0); | |
513 XSET (name, Lisp_String, XSYMBOL (sym)->name); | |
514 return name; | |
515 } | |
516 | |
517 DEFUN ("fset", Ffset, Sfset, 2, 2, 0, | |
518 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.") | |
519 (sym, newdef) | |
520 register Lisp_Object sym, newdef; | |
521 { | |
522 CHECK_SYMBOL (sym, 0); | |
490 | 523 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound)) |
298 | 524 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function), |
525 Vautoload_queue); | |
526 XSYMBOL (sym)->function = newdef; | |
527 return newdef; | |
528 } | |
529 | |
530 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0, | |
531 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.") | |
532 (sym, newplist) | |
533 register Lisp_Object sym, newplist; | |
534 { | |
535 CHECK_SYMBOL (sym, 0); | |
536 XSYMBOL (sym)->plist = newplist; | |
537 return newplist; | |
538 } | |
648 | 539 |
298 | 540 |
541 /* Getting and setting values of symbols */ | |
542 | |
543 /* Given the raw contents of a symbol value cell, | |
544 return the Lisp value of the symbol. | |
545 This does not handle buffer-local variables; use | |
546 swap_in_symval_forwarding for that. */ | |
547 | |
548 Lisp_Object | |
549 do_symval_forwarding (valcontents) | |
550 register Lisp_Object valcontents; | |
551 { | |
552 register Lisp_Object val; | |
553 #ifdef SWITCH_ENUM_BUG | |
554 switch ((int) XTYPE (valcontents)) | |
555 #else | |
556 switch (XTYPE (valcontents)) | |
557 #endif | |
558 { | |
559 case Lisp_Intfwd: | |
560 XSET (val, Lisp_Int, *XINTPTR (valcontents)); | |
561 return val; | |
562 | |
563 case Lisp_Boolfwd: | |
564 if (*XINTPTR (valcontents)) | |
565 return Qt; | |
566 return Qnil; | |
567 | |
568 case Lisp_Objfwd: | |
569 return *XOBJFWD (valcontents); | |
570 | |
571 case Lisp_Buffer_Objfwd: | |
572 return *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer); | |
573 } | |
574 return valcontents; | |
575 } | |
576 | |
577 /* Store NEWVAL into SYM, where VALCONTENTS is found in the value cell | |
578 of SYM. If SYM is buffer-local, VALCONTENTS should be the | |
579 buffer-independent contents of the value cell: forwarded just one | |
580 step past the buffer-localness. */ | |
581 | |
582 void | |
583 store_symval_forwarding (sym, valcontents, newval) | |
584 Lisp_Object sym; | |
585 register Lisp_Object valcontents, newval; | |
586 { | |
587 #ifdef SWITCH_ENUM_BUG | |
588 switch ((int) XTYPE (valcontents)) | |
589 #else | |
590 switch (XTYPE (valcontents)) | |
591 #endif | |
592 { | |
593 case Lisp_Intfwd: | |
594 CHECK_NUMBER (newval, 1); | |
595 *XINTPTR (valcontents) = XINT (newval); | |
596 break; | |
597 | |
598 case Lisp_Boolfwd: | |
490 | 599 *XINTPTR (valcontents) = NILP(newval) ? 0 : 1; |
298 | 600 break; |
601 | |
602 case Lisp_Objfwd: | |
603 *XOBJFWD (valcontents) = newval; | |
604 break; | |
605 | |
606 case Lisp_Buffer_Objfwd: | |
607 *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer) = newval; | |
608 break; | |
609 | |
610 default: | |
611 valcontents = XSYMBOL (sym)->value; | |
612 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
613 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
614 XCONS (XSYMBOL (sym)->value)->car = newval; | |
615 else | |
616 XSYMBOL (sym)->value = newval; | |
617 } | |
618 } | |
619 | |
620 /* Set up the buffer-local symbol SYM for validity in the current | |
621 buffer. VALCONTENTS is the contents of its value cell. | |
622 Return the value forwarded one step past the buffer-local indicator. */ | |
623 | |
624 static Lisp_Object | |
625 swap_in_symval_forwarding (sym, valcontents) | |
626 Lisp_Object sym, valcontents; | |
627 { | |
628 /* valcontents is a list | |
629 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)). | |
630 | |
631 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's | |
632 local_var_alist, that being the element whose car is this variable. | |
633 Or it can be a pointer to the (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER | |
634 does not have an element in its alist for this variable. | |
635 | |
636 If the current buffer is not BUFFER, we store the current REALVALUE value into | |
637 CURRENT-ALIST-ELEMENT, then find the appropriate alist element for | |
638 the buffer now current and set up CURRENT-ALIST-ELEMENT. | |
639 Then we set REALVALUE out of that element, and store into BUFFER. | |
640 Note that REALVALUE can be a forwarding pointer. */ | |
641 | |
642 register Lisp_Object tem1; | |
643 tem1 = XCONS (XCONS (valcontents)->cdr)->car; | |
644 | |
490 | 645 if (NILP (tem1) || current_buffer != XBUFFER (tem1)) |
298 | 646 { |
647 tem1 = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
648 Fsetcdr (tem1, do_symval_forwarding (XCONS (valcontents)->car)); | |
649 tem1 = assq_no_quit (sym, current_buffer->local_var_alist); | |
490 | 650 if (NILP (tem1)) |
298 | 651 tem1 = XCONS (XCONS (valcontents)->cdr)->cdr; |
652 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car = tem1; | |
653 XSET (XCONS (XCONS (valcontents)->cdr)->car, Lisp_Buffer, current_buffer); | |
654 store_symval_forwarding (sym, XCONS (valcontents)->car, Fcdr (tem1)); | |
655 } | |
656 return XCONS (valcontents)->car; | |
657 } | |
658 | |
514 | 659 /* Find the value of a symbol, returning Qunbound if it's not bound. |
660 This is helpful for code which just wants to get a variable's value | |
661 if it has one, without signalling an error. | |
662 Note that it must not be possible to quit | |
663 within this function. Great care is required for this. */ | |
298 | 664 |
514 | 665 Lisp_Object |
666 find_symbol_value (sym) | |
298 | 667 Lisp_Object sym; |
668 { | |
669 register Lisp_Object valcontents, tem1; | |
670 register Lisp_Object val; | |
671 CHECK_SYMBOL (sym, 0); | |
672 valcontents = XSYMBOL (sym)->value; | |
673 | |
674 retry: | |
675 #ifdef SWITCH_ENUM_BUG | |
676 switch ((int) XTYPE (valcontents)) | |
677 #else | |
678 switch (XTYPE (valcontents)) | |
679 #endif | |
680 { | |
681 case Lisp_Buffer_Local_Value: | |
682 case Lisp_Some_Buffer_Local_Value: | |
683 valcontents = swap_in_symval_forwarding (sym, valcontents); | |
684 goto retry; | |
685 | |
686 case Lisp_Intfwd: | |
687 XSET (val, Lisp_Int, *XINTPTR (valcontents)); | |
688 return val; | |
689 | |
690 case Lisp_Boolfwd: | |
691 if (*XINTPTR (valcontents)) | |
692 return Qt; | |
693 return Qnil; | |
694 | |
695 case Lisp_Objfwd: | |
696 return *XOBJFWD (valcontents); | |
697 | |
698 case Lisp_Buffer_Objfwd: | |
699 return *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer); | |
700 | |
701 case Lisp_Void: | |
514 | 702 return Qunbound; |
298 | 703 } |
704 | |
705 return valcontents; | |
706 } | |
707 | |
514 | 708 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0, |
709 "Return SYMBOL's value. Error if that is void.") | |
710 (sym) | |
711 Lisp_Object sym; | |
712 { | |
713 Lisp_Object val = find_symbol_value (sym); | |
714 | |
715 if (EQ (val, Qunbound)) | |
716 return Fsignal (Qvoid_variable, Fcons (sym, Qnil)); | |
717 else | |
718 return val; | |
719 } | |
720 | |
298 | 721 DEFUN ("set", Fset, Sset, 2, 2, 0, |
722 "Set SYMBOL's value to NEWVAL, and return NEWVAL.") | |
723 (sym, newval) | |
724 register Lisp_Object sym, newval; | |
725 { | |
726 int voide = (XTYPE (newval) == Lisp_Void || EQ (newval, Qunbound)); | |
727 | |
728 #ifndef RTPC_REGISTER_BUG | |
729 register Lisp_Object valcontents, tem1, current_alist_element; | |
730 #else /* RTPC_REGISTER_BUG */ | |
731 register Lisp_Object tem1; | |
732 Lisp_Object valcontents, current_alist_element; | |
733 #endif /* RTPC_REGISTER_BUG */ | |
734 | |
735 CHECK_SYMBOL (sym, 0); | |
490 | 736 if (NILP (sym) || EQ (sym, Qt)) |
298 | 737 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
738 valcontents = XSYMBOL (sym)->value; | |
739 | |
740 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
741 { | |
742 register int idx = XUINT (valcontents); | |
743 register int mask = *(int *)(idx + (char *) &buffer_local_flags); | |
744 if (mask > 0) | |
745 current_buffer->local_var_flags |= mask; | |
746 } | |
747 | |
733 | 748 else if (XTYPE (valcontents) == Lisp_Buffer_Local_Value |
749 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
298 | 750 { |
733 | 751 /* valcontents is actually a pointer to a cons heading something like: |
752 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE). | |
753 | |
754 BUFFER is the last buffer for which this symbol's value was | |
755 made up to date. | |
298 | 756 |
733 | 757 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's |
758 local_var_alist, that being the element whose car is this | |
759 variable. Or it can be a pointer to the | |
760 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not | |
761 have an element in its alist for this variable (that is, if | |
762 BUFFER sees the default value of this variable). | |
763 | |
764 If we want to examine or set the value and BUFFER is current, | |
765 we just examine or set REALVALUE. If BUFFER is not current, we | |
766 store the current REALVALUE value into CURRENT-ALIST-ELEMENT, | |
767 then find the appropriate alist element for the buffer now | |
768 current and set up CURRENT-ALIST-ELEMENT. Then we set | |
769 REALVALUE out of that element, and store into BUFFER. | |
298 | 770 |
733 | 771 If we are setting the variable and the current buffer does |
772 not have an alist entry for this variable, an alist entry is | |
773 created. | |
774 | |
775 Note that REALVALUE can be a forwarding pointer. Each time | |
776 it is examined or set, forwarding must be done. */ | |
777 | |
778 /* What value are we caching right now? */ | |
779 current_alist_element = | |
780 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
298 | 781 |
733 | 782 /* If the current buffer is not the buffer whose binding is |
783 currently cached, or if it's a Lisp_Buffer_Local_Value and | |
784 we're looking at the default value, the cache is invalid; we | |
785 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */ | |
786 if ((current_buffer | |
787 != XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)) | |
788 || (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
789 && XCONS (current_alist_element)->car == current_alist_element)) | |
298 | 790 { |
733 | 791 /* Write out the cached value for the old buffer; copy it |
792 back to its alist element. This works if the current | |
793 buffer only sees the default value, too. */ | |
794 Fsetcdr (current_alist_element, | |
795 do_symval_forwarding (XCONS (valcontents)->car)); | |
298 | 796 |
733 | 797 /* Find the new value for CURRENT-ALIST-ELEMENT. */ |
298 | 798 tem1 = Fassq (sym, current_buffer->local_var_alist); |
490 | 799 if (NILP (tem1)) |
733 | 800 { |
801 /* This buffer still sees the default value. */ | |
802 | |
803 /* If the variable is a Lisp_Some_Buffer_Local_Value, | |
804 make CURRENT-ALIST-ELEMENT point to itself, | |
805 indicating that we're seeing the default value. */ | |
806 if (XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
807 tem1 = XCONS (XCONS (valcontents)->cdr)->cdr; | |
808 | |
809 /* If it's a Lisp_Buffer_Local_Value, give this buffer a | |
810 new assoc for a local value and set | |
811 CURRENT-ALIST-ELEMENT to point to that. */ | |
812 else | |
813 { | |
814 tem1 = Fcons (sym, Fcdr (current_alist_element)); | |
815 current_buffer->local_var_alist = | |
816 Fcons (tem1, current_buffer->local_var_alist); | |
817 } | |
818 } | |
819 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */ | |
298 | 820 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car = tem1; |
733 | 821 |
822 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */ | |
823 XSET (XCONS (XCONS (valcontents)->cdr)->car, | |
824 Lisp_Buffer, current_buffer); | |
298 | 825 } |
826 valcontents = XCONS (valcontents)->car; | |
827 } | |
733 | 828 |
298 | 829 /* If storing void (making the symbol void), forward only through |
830 buffer-local indicator, not through Lisp_Objfwd, etc. */ | |
831 if (voide) | |
832 store_symval_forwarding (sym, Qnil, newval); | |
833 else | |
834 store_symval_forwarding (sym, valcontents, newval); | |
733 | 835 |
298 | 836 return newval; |
837 } | |
838 | |
839 /* Access or set a buffer-local symbol's default value. */ | |
840 | |
841 /* Return the default value of SYM, but don't check for voidness. | |
842 Return Qunbound or a Lisp_Void object if it is void. */ | |
843 | |
844 Lisp_Object | |
845 default_value (sym) | |
846 Lisp_Object sym; | |
847 { | |
848 register Lisp_Object valcontents; | |
849 | |
850 CHECK_SYMBOL (sym, 0); | |
851 valcontents = XSYMBOL (sym)->value; | |
852 | |
853 /* For a built-in buffer-local variable, get the default value | |
854 rather than letting do_symval_forwarding get the current value. */ | |
855 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
856 { | |
857 register int idx = XUINT (valcontents); | |
858 | |
859 if (*(int *) (idx + (char *) &buffer_local_flags) != 0) | |
860 return *(Lisp_Object *)(idx + (char *) &buffer_defaults); | |
861 } | |
862 | |
863 /* Handle user-created local variables. */ | |
864 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
865 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
866 { | |
867 /* If var is set up for a buffer that lacks a local value for it, | |
868 the current value is nominally the default value. | |
869 But the current value slot may be more up to date, since | |
870 ordinary setq stores just that slot. So use that. */ | |
871 Lisp_Object current_alist_element, alist_element_car; | |
872 current_alist_element | |
873 = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
874 alist_element_car = XCONS (current_alist_element)->car; | |
875 if (EQ (alist_element_car, current_alist_element)) | |
876 return do_symval_forwarding (XCONS (valcontents)->car); | |
877 else | |
878 return XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->cdr; | |
879 } | |
880 /* For other variables, get the current value. */ | |
881 return do_symval_forwarding (valcontents); | |
882 } | |
883 | |
884 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0, | |
885 "Return T if SYMBOL has a non-void default value.\n\ | |
886 This is the value that is seen in buffers that do not have their own values\n\ | |
887 for this variable.") | |
888 (sym) | |
889 Lisp_Object sym; | |
890 { | |
891 register Lisp_Object value; | |
892 | |
893 value = default_value (sym); | |
894 return (XTYPE (value) == Lisp_Void || EQ (value, Qunbound) | |
895 ? Qnil : Qt); | |
896 } | |
897 | |
898 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0, | |
899 "Return SYMBOL's default value.\n\ | |
900 This is the value that is seen in buffers that do not have their own values\n\ | |
901 for this variable. The default value is meaningful for variables with\n\ | |
902 local bindings in certain buffers.") | |
903 (sym) | |
904 Lisp_Object sym; | |
905 { | |
906 register Lisp_Object value; | |
907 | |
908 value = default_value (sym); | |
909 if (XTYPE (value) == Lisp_Void || EQ (value, Qunbound)) | |
910 return Fsignal (Qvoid_variable, Fcons (sym, Qnil)); | |
911 return value; | |
912 } | |
913 | |
914 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0, | |
915 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\ | |
916 The default value is seen in buffers that do not have their own values\n\ | |
917 for this variable.") | |
918 (sym, value) | |
919 Lisp_Object sym, value; | |
920 { | |
921 register Lisp_Object valcontents, current_alist_element, alist_element_buffer; | |
922 | |
923 CHECK_SYMBOL (sym, 0); | |
924 valcontents = XSYMBOL (sym)->value; | |
925 | |
926 /* Handle variables like case-fold-search that have special slots | |
927 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value | |
928 variables. */ | |
929 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
930 { | |
931 register int idx = XUINT (valcontents); | |
932 #ifndef RTPC_REGISTER_BUG | |
933 register struct buffer *b; | |
934 #else | |
935 struct buffer *b; | |
936 #endif | |
937 register int mask = *(int *) (idx + (char *) &buffer_local_flags); | |
938 | |
939 if (mask > 0) | |
940 { | |
941 *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value; | |
942 for (b = all_buffers; b; b = b->next) | |
943 if (!(b->local_var_flags & mask)) | |
944 *(Lisp_Object *)(idx + (char *) b) = value; | |
945 } | |
946 return value; | |
947 } | |
948 | |
949 if (XTYPE (valcontents) != Lisp_Buffer_Local_Value && | |
950 XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
951 return Fset (sym, value); | |
952 | |
953 /* Store new value into the DEFAULT-VALUE slot */ | |
954 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->cdr = value; | |
955 | |
956 /* If that slot is current, we must set the REALVALUE slot too */ | |
957 current_alist_element = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
958 alist_element_buffer = Fcar (current_alist_element); | |
959 if (EQ (alist_element_buffer, current_alist_element)) | |
960 store_symval_forwarding (sym, XCONS (valcontents)->car, value); | |
961 | |
962 return value; | |
963 } | |
964 | |
965 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 2, UNEVALLED, 0, | |
966 "\ | |
967 (setq-default SYM VAL SYM VAL ...): set each SYM's default value to its VAL.\n\ | |
968 VAL is evaluated; SYM is not. The default value is seen in buffers that do\n\ | |
969 not have their own values for this variable.") | |
970 (args) | |
971 Lisp_Object args; | |
972 { | |
973 register Lisp_Object args_left; | |
974 register Lisp_Object val, sym; | |
975 struct gcpro gcpro1; | |
976 | |
490 | 977 if (NILP (args)) |
298 | 978 return Qnil; |
979 | |
980 args_left = args; | |
981 GCPRO1 (args); | |
982 | |
983 do | |
984 { | |
985 val = Feval (Fcar (Fcdr (args_left))); | |
986 sym = Fcar (args_left); | |
987 Fset_default (sym, val); | |
988 args_left = Fcdr (Fcdr (args_left)); | |
989 } | |
490 | 990 while (!NILP (args_left)); |
298 | 991 |
992 UNGCPRO; | |
993 return val; | |
994 } | |
995 | |
996 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local, | |
997 1, 1, "vMake Variable Buffer Local: ", | |
998 "Make VARIABLE have a separate value for each buffer.\n\ | |
999 At any time, the value for the current buffer is in effect.\n\ | |
1000 There is also a default value which is seen in any buffer which has not yet\n\ | |
1001 set its own value.\n\ | |
1002 Using `set' or `setq' to set the variable causes it to have a separate value\n\ | |
1003 for the current buffer if it was previously using the default value.\n\ | |
1004 The function `default-value' gets the default value and `set-default' sets it.") | |
1005 (sym) | |
1006 register Lisp_Object sym; | |
1007 { | |
1008 register Lisp_Object tem, valcontents; | |
1009 | |
1010 CHECK_SYMBOL (sym, 0); | |
1011 | |
1012 if (EQ (sym, Qnil) || EQ (sym, Qt)) | |
1013 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data); | |
1014 | |
1015 valcontents = XSYMBOL (sym)->value; | |
1016 if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value) || | |
1017 (XTYPE (valcontents) == Lisp_Buffer_Objfwd)) | |
1018 return sym; | |
1019 if (XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
1020 { | |
1021 XSETTYPE (XSYMBOL (sym)->value, Lisp_Buffer_Local_Value); | |
1022 return sym; | |
1023 } | |
1024 if (EQ (valcontents, Qunbound)) | |
1025 XSYMBOL (sym)->value = Qnil; | |
1026 tem = Fcons (Qnil, Fsymbol_value (sym)); | |
1027 XCONS (tem)->car = tem; | |
1028 XSYMBOL (sym)->value = Fcons (XSYMBOL (sym)->value, Fcons (Fcurrent_buffer (), tem)); | |
1029 XSETTYPE (XSYMBOL (sym)->value, Lisp_Buffer_Local_Value); | |
1030 return sym; | |
1031 } | |
1032 | |
1033 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, | |
1034 1, 1, "vMake Local Variable: ", | |
1035 "Make VARIABLE have a separate value in the current buffer.\n\ | |
1036 Other buffers will continue to share a common default value.\n\ | |
1037 See also `make-variable-buffer-local'.\n\n\ | |
1038 If the variable is already arranged to become local when set,\n\ | |
1039 this function causes a local value to exist for this buffer,\n\ | |
1040 just as if the variable were set.") | |
1041 (sym) | |
1042 register Lisp_Object sym; | |
1043 { | |
1044 register Lisp_Object tem, valcontents; | |
1045 | |
1046 CHECK_SYMBOL (sym, 0); | |
1047 | |
1048 if (EQ (sym, Qnil) || EQ (sym, Qt)) | |
1049 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data); | |
1050 | |
1051 valcontents = XSYMBOL (sym)->value; | |
1052 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
1053 || XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
1054 { | |
1055 tem = Fboundp (sym); | |
1056 | |
1057 /* Make sure the symbol has a local value in this particular buffer, | |
1058 by setting it to the same value it already has. */ | |
1059 Fset (sym, (EQ (tem, Qt) ? Fsymbol_value (sym) : Qunbound)); | |
1060 return sym; | |
1061 } | |
1062 /* Make sure sym is set up to hold per-buffer values */ | |
1063 if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
1064 { | |
1065 if (EQ (valcontents, Qunbound)) | |
1066 XSYMBOL (sym)->value = Qnil; | |
1067 tem = Fcons (Qnil, do_symval_forwarding (valcontents)); | |
1068 XCONS (tem)->car = tem; | |
1069 XSYMBOL (sym)->value = Fcons (XSYMBOL (sym)->value, Fcons (Qnil, tem)); | |
1070 XSETTYPE (XSYMBOL (sym)->value, Lisp_Some_Buffer_Local_Value); | |
1071 } | |
1072 /* Make sure this buffer has its own value of sym */ | |
1073 tem = Fassq (sym, current_buffer->local_var_alist); | |
490 | 1074 if (NILP (tem)) |
298 | 1075 { |
1076 current_buffer->local_var_alist | |
1077 = Fcons (Fcons (sym, XCONS (XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->cdr)->cdr), | |
1078 current_buffer->local_var_alist); | |
1079 | |
1080 /* Make sure symbol does not think it is set up for this buffer; | |
1081 force it to look once again for this buffer's value */ | |
1082 { | |
1083 /* This local variable avoids "expression too complex" on IBM RT. */ | |
1084 Lisp_Object xs; | |
1085 | |
1086 xs = XSYMBOL (sym)->value; | |
1087 if (current_buffer == XBUFFER (XCONS (XCONS (xs)->cdr)->car)) | |
1088 XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car = Qnil; | |
1089 } | |
1090 | |
1091 } | |
1092 return sym; | |
1093 } | |
1094 | |
1095 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable, | |
1096 1, 1, "vKill Local Variable: ", | |
1097 "Make VARIABLE no longer have a separate value in the current buffer.\n\ | |
1098 From now on the default value will apply in this buffer.") | |
1099 (sym) | |
1100 register Lisp_Object sym; | |
1101 { | |
1102 register Lisp_Object tem, valcontents; | |
1103 | |
1104 CHECK_SYMBOL (sym, 0); | |
1105 | |
1106 valcontents = XSYMBOL (sym)->value; | |
1107 | |
1108 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
1109 { | |
1110 register int idx = XUINT (valcontents); | |
1111 register int mask = *(int *) (idx + (char *) &buffer_local_flags); | |
1112 | |
1113 if (mask > 0) | |
1114 { | |
1115 *(Lisp_Object *)(idx + (char *) current_buffer) | |
1116 = *(Lisp_Object *)(idx + (char *) &buffer_defaults); | |
1117 current_buffer->local_var_flags &= ~mask; | |
1118 } | |
1119 return sym; | |
1120 } | |
1121 | |
1122 if (XTYPE (valcontents) != Lisp_Buffer_Local_Value && | |
1123 XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
1124 return sym; | |
1125 | |
1126 /* Get rid of this buffer's alist element, if any */ | |
1127 | |
1128 tem = Fassq (sym, current_buffer->local_var_alist); | |
490 | 1129 if (!NILP (tem)) |
298 | 1130 current_buffer->local_var_alist = Fdelq (tem, current_buffer->local_var_alist); |
1131 | |
1132 /* Make sure symbol does not think it is set up for this buffer; | |
1133 force it to look once again for this buffer's value */ | |
1134 { | |
1135 Lisp_Object sv; | |
1136 sv = XSYMBOL (sym)->value; | |
1137 if (current_buffer == XBUFFER (XCONS (XCONS (sv)->cdr)->car)) | |
1138 XCONS (XCONS (sv)->cdr)->car = Qnil; | |
1139 } | |
1140 | |
1141 return sym; | |
1142 } | |
1143 | |
648 | 1144 /* Find the function at the end of a chain of symbol function indirections. */ |
1145 | |
1146 /* If OBJECT is a symbol, find the end of its function chain and | |
1147 return the value found there. If OBJECT is not a symbol, just | |
1148 return it. If there is a cycle in the function chain, signal a | |
1149 cyclic-function-indirection error. | |
1150 | |
1151 This is like Findirect_function, except that it doesn't signal an | |
1152 error if the chain ends up unbound. */ | |
1153 Lisp_Object | |
1154 indirect_function (object, error) | |
1155 register Lisp_Object object; | |
1156 { | |
1157 Lisp_Object tortise, hare; | |
1158 | |
1159 hare = tortise = object; | |
1160 | |
1161 for (;;) | |
1162 { | |
1163 if (XTYPE (hare) != Lisp_Symbol || EQ (hare, Qunbound)) | |
1164 break; | |
1165 hare = XSYMBOL (hare)->function; | |
1166 if (XTYPE (hare) != Lisp_Symbol || EQ (hare, Qunbound)) | |
1167 break; | |
1168 hare = XSYMBOL (hare)->function; | |
1169 | |
1170 tortise = XSYMBOL (tortise)->function; | |
1171 | |
1172 if (EQ (hare, tortise)) | |
1173 Fsignal (Qcyclic_function_indirection, Fcons (object, Qnil)); | |
1174 } | |
1175 | |
1176 return hare; | |
1177 } | |
1178 | |
1179 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 1, 0, | |
1180 "Return the function at the end of OBJECT's function chain.\n\ | |
1181 If OBJECT is a symbol, follow all function indirections and return the final\n\ | |
1182 function binding.\n\ | |
1183 If OBJECT is not a symbol, just return it.\n\ | |
1184 Signal a void-function error if the final symbol is unbound.\n\ | |
1185 Signal a cyclic-function-indirection error if there is a loop in the\n\ | |
1186 function chain of symbols.") | |
1187 (object) | |
1188 register Lisp_Object object; | |
1189 { | |
1190 Lisp_Object result; | |
1191 | |
1192 result = indirect_function (object); | |
1193 | |
1194 if (EQ (result, Qunbound)) | |
1195 return Fsignal (Qvoid_function, Fcons (object, Qnil)); | |
1196 return result; | |
1197 } | |
1198 | |
298 | 1199 /* Extract and set vector and string elements */ |
1200 | |
1201 DEFUN ("aref", Faref, Saref, 2, 2, 0, | |
1202 "Return the element of ARRAY at index INDEX.\n\ | |
1203 ARRAY may be a vector or a string, or a byte-code object. INDEX starts at 0.") | |
1204 (array, idx) | |
1205 register Lisp_Object array; | |
1206 Lisp_Object idx; | |
1207 { | |
1208 register int idxval; | |
1209 | |
1210 CHECK_NUMBER (idx, 1); | |
1211 idxval = XINT (idx); | |
1212 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String | |
1213 && XTYPE (array) != Lisp_Compiled) | |
1214 array = wrong_type_argument (Qarrayp, array); | |
1215 if (idxval < 0 || idxval >= XVECTOR (array)->size) | |
1216 args_out_of_range (array, idx); | |
1217 if (XTYPE (array) == Lisp_String) | |
1218 { | |
1219 Lisp_Object val; | |
1220 XFASTINT (val) = (unsigned char) XSTRING (array)->data[idxval]; | |
1221 return val; | |
1222 } | |
1223 else | |
1224 return XVECTOR (array)->contents[idxval]; | |
1225 } | |
1226 | |
1227 DEFUN ("aset", Faset, Saset, 3, 3, 0, | |
1228 "Store into the element of ARRAY at index INDEX the value NEWVAL.\n\ | |
1229 ARRAY may be a vector or a string. INDEX starts at 0.") | |
1230 (array, idx, newelt) | |
1231 register Lisp_Object array; | |
1232 Lisp_Object idx, newelt; | |
1233 { | |
1234 register int idxval; | |
1235 | |
1236 CHECK_NUMBER (idx, 1); | |
1237 idxval = XINT (idx); | |
1238 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String) | |
1239 array = wrong_type_argument (Qarrayp, array); | |
1240 if (idxval < 0 || idxval >= XVECTOR (array)->size) | |
1241 args_out_of_range (array, idx); | |
1242 CHECK_IMPURE (array); | |
1243 | |
1244 if (XTYPE (array) == Lisp_Vector) | |
1245 XVECTOR (array)->contents[idxval] = newelt; | |
1246 else | |
1247 { | |
1248 CHECK_NUMBER (newelt, 2); | |
1249 XSTRING (array)->data[idxval] = XINT (newelt); | |
1250 } | |
1251 | |
1252 return newelt; | |
1253 } | |
1254 | |
1255 Lisp_Object | |
1256 Farray_length (array) | |
1257 register Lisp_Object array; | |
1258 { | |
1259 register Lisp_Object size; | |
1260 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String | |
1261 && XTYPE (array) != Lisp_Compiled) | |
1262 array = wrong_type_argument (Qarrayp, array); | |
1263 XFASTINT (size) = XVECTOR (array)->size; | |
1264 return size; | |
1265 } | |
1266 | |
1267 /* Arithmetic functions */ | |
1268 | |
1269 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal }; | |
1270 | |
1271 Lisp_Object | |
1272 arithcompare (num1, num2, comparison) | |
1273 Lisp_Object num1, num2; | |
1274 enum comparison comparison; | |
1275 { | |
1276 double f1, f2; | |
1277 int floatp = 0; | |
1278 | |
1279 #ifdef LISP_FLOAT_TYPE | |
1280 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0); | |
1281 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 0); | |
1282 | |
1283 if (XTYPE (num1) == Lisp_Float || XTYPE (num2) == Lisp_Float) | |
1284 { | |
1285 floatp = 1; | |
1286 f1 = (XTYPE (num1) == Lisp_Float) ? XFLOAT (num1)->data : XINT (num1); | |
1287 f2 = (XTYPE (num2) == Lisp_Float) ? XFLOAT (num2)->data : XINT (num2); | |
1288 } | |
1289 #else | |
1290 CHECK_NUMBER_COERCE_MARKER (num1, 0); | |
1291 CHECK_NUMBER_COERCE_MARKER (num2, 0); | |
1292 #endif /* LISP_FLOAT_TYPE */ | |
1293 | |
1294 switch (comparison) | |
1295 { | |
1296 case equal: | |
1297 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2)) | |
1298 return Qt; | |
1299 return Qnil; | |
1300 | |
1301 case notequal: | |
1302 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2)) | |
1303 return Qt; | |
1304 return Qnil; | |
1305 | |
1306 case less: | |
1307 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2)) | |
1308 return Qt; | |
1309 return Qnil; | |
1310 | |
1311 case less_or_equal: | |
1312 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2)) | |
1313 return Qt; | |
1314 return Qnil; | |
1315 | |
1316 case grtr: | |
1317 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2)) | |
1318 return Qt; | |
1319 return Qnil; | |
1320 | |
1321 case grtr_or_equal: | |
1322 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) | |
1323 return Qt; | |
1324 return Qnil; | |
1325 } | |
1326 } | |
1327 | |
1328 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0, | |
1329 "T if two args, both numbers or markers, are equal.") | |
1330 (num1, num2) | |
1331 register Lisp_Object num1, num2; | |
1332 { | |
1333 return arithcompare (num1, num2, equal); | |
1334 } | |
1335 | |
1336 DEFUN ("<", Flss, Slss, 2, 2, 0, | |
1337 "T if first arg is less than second arg. Both must be numbers or markers.") | |
1338 (num1, num2) | |
1339 register Lisp_Object num1, num2; | |
1340 { | |
1341 return arithcompare (num1, num2, less); | |
1342 } | |
1343 | |
1344 DEFUN (">", Fgtr, Sgtr, 2, 2, 0, | |
1345 "T if first arg is greater than second arg. Both must be numbers or markers.") | |
1346 (num1, num2) | |
1347 register Lisp_Object num1, num2; | |
1348 { | |
1349 return arithcompare (num1, num2, grtr); | |
1350 } | |
1351 | |
1352 DEFUN ("<=", Fleq, Sleq, 2, 2, 0, | |
1353 "T if first arg is less than or equal to second arg.\n\ | |
1354 Both must be numbers or markers.") | |
1355 (num1, num2) | |
1356 register Lisp_Object num1, num2; | |
1357 { | |
1358 return arithcompare (num1, num2, less_or_equal); | |
1359 } | |
1360 | |
1361 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0, | |
1362 "T if first arg is greater than or equal to second arg.\n\ | |
1363 Both must be numbers or markers.") | |
1364 (num1, num2) | |
1365 register Lisp_Object num1, num2; | |
1366 { | |
1367 return arithcompare (num1, num2, grtr_or_equal); | |
1368 } | |
1369 | |
1370 DEFUN ("/=", Fneq, Sneq, 2, 2, 0, | |
1371 "T if first arg is not equal to second arg. Both must be numbers or markers.") | |
1372 (num1, num2) | |
1373 register Lisp_Object num1, num2; | |
1374 { | |
1375 return arithcompare (num1, num2, notequal); | |
1376 } | |
1377 | |
1378 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.") | |
1379 (num) | |
1380 register Lisp_Object num; | |
1381 { | |
1382 #ifdef LISP_FLOAT_TYPE | |
1383 CHECK_NUMBER_OR_FLOAT (num, 0); | |
1384 | |
1385 if (XTYPE(num) == Lisp_Float) | |
1386 { | |
1387 if (XFLOAT(num)->data == 0.0) | |
1388 return Qt; | |
1389 return Qnil; | |
1390 } | |
1391 #else | |
1392 CHECK_NUMBER (num, 0); | |
1393 #endif /* LISP_FLOAT_TYPE */ | |
1394 | |
1395 if (!XINT (num)) | |
1396 return Qt; | |
1397 return Qnil; | |
1398 } | |
1399 | |
1400 DEFUN ("int-to-string", Fint_to_string, Sint_to_string, 1, 1, 0, | |
1401 "Convert INT to a string by printing it in decimal.\n\ | |
1402 Uses a minus sign if negative.") | |
1403 (num) | |
1404 Lisp_Object num; | |
1405 { | |
1406 char buffer[20]; | |
1407 | |
1408 #ifndef LISP_FLOAT_TYPE | |
1409 CHECK_NUMBER (num, 0); | |
1410 #else | |
1411 CHECK_NUMBER_OR_FLOAT (num, 0); | |
1412 | |
1413 if (XTYPE(num) == Lisp_Float) | |
1414 { | |
1415 char pigbuf[350]; /* see comments in float_to_string */ | |
1416 | |
1417 float_to_string (pigbuf, XFLOAT(num)->data); | |
1418 return build_string (pigbuf); | |
1419 } | |
1420 #endif /* LISP_FLOAT_TYPE */ | |
1421 | |
1422 sprintf (buffer, "%d", XINT (num)); | |
1423 return build_string (buffer); | |
1424 } | |
1425 | |
1426 DEFUN ("string-to-int", Fstring_to_int, Sstring_to_int, 1, 1, 0, | |
1427 "Convert STRING to an integer by parsing it as a decimal number.") | |
1428 (str) | |
1429 register Lisp_Object str; | |
1430 { | |
1431 CHECK_STRING (str, 0); | |
1432 | |
1433 #ifdef LISP_FLOAT_TYPE | |
1434 if (isfloat_string (XSTRING (str)->data)) | |
1435 return make_float (atof (XSTRING (str)->data)); | |
1436 #endif /* LISP_FLOAT_TYPE */ | |
1437 | |
1438 return make_number (atoi (XSTRING (str)->data)); | |
1439 } | |
1440 | |
1441 enum arithop | |
1442 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin }; | |
1443 | |
1444 Lisp_Object | |
1445 arith_driver | |
1446 (code, nargs, args) | |
1447 enum arithop code; | |
1448 int nargs; | |
1449 register Lisp_Object *args; | |
1450 { | |
1451 register Lisp_Object val; | |
1452 register int argnum; | |
1453 register int accum; | |
1454 register int next; | |
1455 | |
1456 #ifdef SWITCH_ENUM_BUG | |
1457 switch ((int) code) | |
1458 #else | |
1459 switch (code) | |
1460 #endif | |
1461 { | |
1462 case Alogior: | |
1463 case Alogxor: | |
1464 case Aadd: | |
1465 case Asub: | |
1466 accum = 0; break; | |
1467 case Amult: | |
1468 accum = 1; break; | |
1469 case Alogand: | |
1470 accum = -1; break; | |
1471 } | |
1472 | |
1473 for (argnum = 0; argnum < nargs; argnum++) | |
1474 { | |
1475 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
1476 #ifdef LISP_FLOAT_TYPE | |
1477 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum); | |
1478 | |
1479 if (XTYPE (val) == Lisp_Float) /* time to do serious math */ | |
1480 return (float_arith_driver ((double) accum, argnum, code, | |
1481 nargs, args)); | |
1482 #else | |
1483 CHECK_NUMBER_COERCE_MARKER (val, argnum); | |
1484 #endif /* LISP_FLOAT_TYPE */ | |
1485 args[argnum] = val; /* runs into a compiler bug. */ | |
1486 next = XINT (args[argnum]); | |
1487 #ifdef SWITCH_ENUM_BUG | |
1488 switch ((int) code) | |
1489 #else | |
1490 switch (code) | |
1491 #endif | |
1492 { | |
1493 case Aadd: accum += next; break; | |
1494 case Asub: | |
1495 if (!argnum && nargs != 1) | |
1496 next = - next; | |
1497 accum -= next; | |
1498 break; | |
1499 case Amult: accum *= next; break; | |
1500 case Adiv: | |
1501 if (!argnum) accum = next; | |
1502 else accum /= next; | |
1503 break; | |
1504 case Alogand: accum &= next; break; | |
1505 case Alogior: accum |= next; break; | |
1506 case Alogxor: accum ^= next; break; | |
1507 case Amax: if (!argnum || next > accum) accum = next; break; | |
1508 case Amin: if (!argnum || next < accum) accum = next; break; | |
1509 } | |
1510 } | |
1511 | |
1512 XSET (val, Lisp_Int, accum); | |
1513 return val; | |
1514 } | |
1515 | |
1516 #ifdef LISP_FLOAT_TYPE | |
1517 Lisp_Object | |
1518 float_arith_driver (accum, argnum, code, nargs, args) | |
1519 double accum; | |
1520 register int argnum; | |
1521 enum arithop code; | |
1522 int nargs; | |
1523 register Lisp_Object *args; | |
1524 { | |
1525 register Lisp_Object val; | |
1526 double next; | |
1527 | |
1528 for (; argnum < nargs; argnum++) | |
1529 { | |
1530 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
1531 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum); | |
1532 | |
1533 if (XTYPE (val) == Lisp_Float) | |
1534 { | |
1535 next = XFLOAT (val)->data; | |
1536 } | |
1537 else | |
1538 { | |
1539 args[argnum] = val; /* runs into a compiler bug. */ | |
1540 next = XINT (args[argnum]); | |
1541 } | |
1542 #ifdef SWITCH_ENUM_BUG | |
1543 switch ((int) code) | |
1544 #else | |
1545 switch (code) | |
1546 #endif | |
1547 { | |
1548 case Aadd: | |
1549 accum += next; | |
1550 break; | |
1551 case Asub: | |
1552 if (!argnum && nargs != 1) | |
1553 next = - next; | |
1554 accum -= next; | |
1555 break; | |
1556 case Amult: | |
1557 accum *= next; | |
1558 break; | |
1559 case Adiv: | |
1560 if (!argnum) | |
1561 accum = next; | |
1562 else | |
1563 accum /= next; | |
1564 break; | |
1565 case Alogand: | |
1566 case Alogior: | |
1567 case Alogxor: | |
1568 return wrong_type_argument (Qinteger_or_marker_p, val); | |
1569 case Amax: | |
1570 if (!argnum || next > accum) | |
1571 accum = next; | |
1572 break; | |
1573 case Amin: | |
1574 if (!argnum || next < accum) | |
1575 accum = next; | |
1576 break; | |
1577 } | |
1578 } | |
1579 | |
1580 return make_float (accum); | |
1581 } | |
1582 #endif /* LISP_FLOAT_TYPE */ | |
1583 | |
1584 DEFUN ("+", Fplus, Splus, 0, MANY, 0, | |
1585 "Return sum of any number of arguments, which are numbers or markers.") | |
1586 (nargs, args) | |
1587 int nargs; | |
1588 Lisp_Object *args; | |
1589 { | |
1590 return arith_driver (Aadd, nargs, args); | |
1591 } | |
1592 | |
1593 DEFUN ("-", Fminus, Sminus, 0, MANY, 0, | |
1594 "Negate number or subtract numbers or markers.\n\ | |
1595 With one arg, negates it. With more than one arg,\n\ | |
1596 subtracts all but the first from the first.") | |
1597 (nargs, args) | |
1598 int nargs; | |
1599 Lisp_Object *args; | |
1600 { | |
1601 return arith_driver (Asub, nargs, args); | |
1602 } | |
1603 | |
1604 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, | |
1605 "Returns product of any number of arguments, which are numbers or markers.") | |
1606 (nargs, args) | |
1607 int nargs; | |
1608 Lisp_Object *args; | |
1609 { | |
1610 return arith_driver (Amult, nargs, args); | |
1611 } | |
1612 | |
1613 DEFUN ("/", Fquo, Squo, 2, MANY, 0, | |
1614 "Returns first argument divided by all the remaining arguments.\n\ | |
1615 The arguments must be numbers or markers.") | |
1616 (nargs, args) | |
1617 int nargs; | |
1618 Lisp_Object *args; | |
1619 { | |
1620 return arith_driver (Adiv, nargs, args); | |
1621 } | |
1622 | |
1623 DEFUN ("%", Frem, Srem, 2, 2, 0, | |
1624 "Returns remainder of first arg divided by second.\n\ | |
1625 Both must be numbers or markers.") | |
1626 (num1, num2) | |
1627 register Lisp_Object num1, num2; | |
1628 { | |
1629 Lisp_Object val; | |
1630 | |
1631 #ifdef LISP_FLOAT_TYPE | |
1632 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0); | |
1633 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 0); | |
1634 | |
1635 if (XTYPE (num1) == Lisp_Float || XTYPE (num2) == Lisp_Float) | |
1636 { | |
1637 double f1, f2; | |
1638 | |
1639 f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1); | |
1640 f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2); | |
733 | 1641 f1 = drem (f1, f2); |
1642 if (f1 < 0) | |
1643 f1 += f2; | |
1644 return (make_float (f1)); | |
298 | 1645 } |
1646 #else /* not LISP_FLOAT_TYPE */ | |
1647 CHECK_NUMBER_COERCE_MARKER (num1, 0); | |
1648 CHECK_NUMBER_COERCE_MARKER (num2, 1); | |
1649 #endif /* not LISP_FLOAT_TYPE */ | |
1650 | |
1651 XSET (val, Lisp_Int, XINT (num1) % XINT (num2)); | |
1652 return val; | |
1653 } | |
1654 | |
1655 DEFUN ("max", Fmax, Smax, 1, MANY, 0, | |
1656 "Return largest of all the arguments (which must be numbers or markers).\n\ | |
1657 The value is always a number; markers are converted to numbers.") | |
1658 (nargs, args) | |
1659 int nargs; | |
1660 Lisp_Object *args; | |
1661 { | |
1662 return arith_driver (Amax, nargs, args); | |
1663 } | |
1664 | |
1665 DEFUN ("min", Fmin, Smin, 1, MANY, 0, | |
1666 "Return smallest of all the arguments (which must be numbers or markers).\n\ | |
1667 The value is always a number; markers are converted to numbers.") | |
1668 (nargs, args) | |
1669 int nargs; | |
1670 Lisp_Object *args; | |
1671 { | |
1672 return arith_driver (Amin, nargs, args); | |
1673 } | |
1674 | |
1675 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0, | |
1676 "Return bitwise-and of all the arguments.\n\ | |
1677 Arguments may be integers, or markers converted to integers.") | |
1678 (nargs, args) | |
1679 int nargs; | |
1680 Lisp_Object *args; | |
1681 { | |
1682 return arith_driver (Alogand, nargs, args); | |
1683 } | |
1684 | |
1685 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0, | |
1686 "Return bitwise-or of all the arguments.\n\ | |
1687 Arguments may be integers, or markers converted to integers.") | |
1688 (nargs, args) | |
1689 int nargs; | |
1690 Lisp_Object *args; | |
1691 { | |
1692 return arith_driver (Alogior, nargs, args); | |
1693 } | |
1694 | |
1695 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0, | |
1696 "Return bitwise-exclusive-or of all the arguments.\n\ | |
1697 Arguments may be integers, or markers converted to integers.") | |
1698 (nargs, args) | |
1699 int nargs; | |
1700 Lisp_Object *args; | |
1701 { | |
1702 return arith_driver (Alogxor, nargs, args); | |
1703 } | |
1704 | |
1705 DEFUN ("ash", Fash, Sash, 2, 2, 0, | |
1706 "Return VALUE with its bits shifted left by COUNT.\n\ | |
1707 If COUNT is negative, shifting is actually to the right.\n\ | |
1708 In this case, the sign bit is duplicated.") | |
1709 (num1, num2) | |
1710 register Lisp_Object num1, num2; | |
1711 { | |
1712 register Lisp_Object val; | |
1713 | |
1714 CHECK_NUMBER (num1, 0); | |
1715 CHECK_NUMBER (num2, 1); | |
1716 | |
1717 if (XINT (num2) > 0) | |
1718 XSET (val, Lisp_Int, XINT (num1) << XFASTINT (num2)); | |
1719 else | |
1720 XSET (val, Lisp_Int, XINT (num1) >> -XINT (num2)); | |
1721 return val; | |
1722 } | |
1723 | |
1724 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0, | |
1725 "Return VALUE with its bits shifted left by COUNT.\n\ | |
1726 If COUNT is negative, shifting is actually to the right.\n\ | |
1727 In this case, zeros are shifted in on the left.") | |
1728 (num1, num2) | |
1729 register Lisp_Object num1, num2; | |
1730 { | |
1731 register Lisp_Object val; | |
1732 | |
1733 CHECK_NUMBER (num1, 0); | |
1734 CHECK_NUMBER (num2, 1); | |
1735 | |
1736 if (XINT (num2) > 0) | |
1737 XSET (val, Lisp_Int, (unsigned) XFASTINT (num1) << XFASTINT (num2)); | |
1738 else | |
1739 XSET (val, Lisp_Int, (unsigned) XFASTINT (num1) >> -XINT (num2)); | |
1740 return val; | |
1741 } | |
1742 | |
1743 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, | |
1744 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\ | |
1745 Markers are converted to integers.") | |
1746 (num) | |
1747 register Lisp_Object num; | |
1748 { | |
1749 #ifdef LISP_FLOAT_TYPE | |
1750 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0); | |
1751 | |
1752 if (XTYPE (num) == Lisp_Float) | |
1753 return (make_float (1.0 + XFLOAT (num)->data)); | |
1754 #else | |
1755 CHECK_NUMBER_COERCE_MARKER (num, 0); | |
1756 #endif /* LISP_FLOAT_TYPE */ | |
1757 | |
1758 XSETINT (num, XFASTINT (num) + 1); | |
1759 return num; | |
1760 } | |
1761 | |
1762 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, | |
1763 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\ | |
1764 Markers are converted to integers.") | |
1765 (num) | |
1766 register Lisp_Object num; | |
1767 { | |
1768 #ifdef LISP_FLOAT_TYPE | |
1769 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0); | |
1770 | |
1771 if (XTYPE (num) == Lisp_Float) | |
1772 return (make_float (-1.0 + XFLOAT (num)->data)); | |
1773 #else | |
1774 CHECK_NUMBER_COERCE_MARKER (num, 0); | |
1775 #endif /* LISP_FLOAT_TYPE */ | |
1776 | |
1777 XSETINT (num, XFASTINT (num) - 1); | |
1778 return num; | |
1779 } | |
1780 | |
1781 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0, | |
1782 "Return the bitwise complement of ARG. ARG must be an integer.") | |
1783 (num) | |
1784 register Lisp_Object num; | |
1785 { | |
1786 CHECK_NUMBER (num, 0); | |
1787 XSETINT (num, ~XFASTINT (num)); | |
1788 return num; | |
1789 } | |
1790 | |
1791 void | |
1792 syms_of_data () | |
1793 { | |
1794 Qquote = intern ("quote"); | |
1795 Qlambda = intern ("lambda"); | |
1796 Qsubr = intern ("subr"); | |
1797 Qerror_conditions = intern ("error-conditions"); | |
1798 Qerror_message = intern ("error-message"); | |
1799 Qtop_level = intern ("top-level"); | |
1800 | |
1801 Qerror = intern ("error"); | |
1802 Qquit = intern ("quit"); | |
1803 Qwrong_type_argument = intern ("wrong-type-argument"); | |
1804 Qargs_out_of_range = intern ("args-out-of-range"); | |
1805 Qvoid_function = intern ("void-function"); | |
648 | 1806 Qcyclic_function_indirection = intern ("cyclic-function-indirection"); |
298 | 1807 Qvoid_variable = intern ("void-variable"); |
1808 Qsetting_constant = intern ("setting-constant"); | |
1809 Qinvalid_read_syntax = intern ("invalid-read-syntax"); | |
1810 | |
1811 Qinvalid_function = intern ("invalid-function"); | |
1812 Qwrong_number_of_arguments = intern ("wrong-number-of-arguments"); | |
1813 Qno_catch = intern ("no-catch"); | |
1814 Qend_of_file = intern ("end-of-file"); | |
1815 Qarith_error = intern ("arith-error"); | |
1816 Qbeginning_of_buffer = intern ("beginning-of-buffer"); | |
1817 Qend_of_buffer = intern ("end-of-buffer"); | |
1818 Qbuffer_read_only = intern ("buffer-read-only"); | |
1819 | |
1820 Qlistp = intern ("listp"); | |
1821 Qconsp = intern ("consp"); | |
1822 Qsymbolp = intern ("symbolp"); | |
1823 Qintegerp = intern ("integerp"); | |
1824 Qnatnump = intern ("natnump"); | |
1825 Qstringp = intern ("stringp"); | |
1826 Qarrayp = intern ("arrayp"); | |
1827 Qsequencep = intern ("sequencep"); | |
1828 Qbufferp = intern ("bufferp"); | |
1829 Qvectorp = intern ("vectorp"); | |
1830 Qchar_or_string_p = intern ("char-or-string-p"); | |
1831 Qmarkerp = intern ("markerp"); | |
1832 Qinteger_or_marker_p = intern ("integer-or-marker-p"); | |
1833 Qboundp = intern ("boundp"); | |
1834 Qfboundp = intern ("fboundp"); | |
1835 | |
1836 #ifdef LISP_FLOAT_TYPE | |
1837 Qfloatp = intern ("floatp"); | |
1838 Qnumberp = intern ("numberp"); | |
1839 Qnumber_or_marker_p = intern ("number-or-marker-p"); | |
1840 #endif /* LISP_FLOAT_TYPE */ | |
1841 | |
1842 Qcdr = intern ("cdr"); | |
1843 | |
1844 /* ERROR is used as a signaler for random errors for which nothing else is right */ | |
1845 | |
1846 Fput (Qerror, Qerror_conditions, | |
1847 Fcons (Qerror, Qnil)); | |
1848 Fput (Qerror, Qerror_message, | |
1849 build_string ("error")); | |
1850 | |
1851 Fput (Qquit, Qerror_conditions, | |
1852 Fcons (Qquit, Qnil)); | |
1853 Fput (Qquit, Qerror_message, | |
1854 build_string ("Quit")); | |
1855 | |
1856 Fput (Qwrong_type_argument, Qerror_conditions, | |
1857 Fcons (Qwrong_type_argument, Fcons (Qerror, Qnil))); | |
1858 Fput (Qwrong_type_argument, Qerror_message, | |
1859 build_string ("Wrong type argument")); | |
1860 | |
1861 Fput (Qargs_out_of_range, Qerror_conditions, | |
1862 Fcons (Qargs_out_of_range, Fcons (Qerror, Qnil))); | |
1863 Fput (Qargs_out_of_range, Qerror_message, | |
1864 build_string ("Args out of range")); | |
1865 | |
1866 Fput (Qvoid_function, Qerror_conditions, | |
1867 Fcons (Qvoid_function, Fcons (Qerror, Qnil))); | |
1868 Fput (Qvoid_function, Qerror_message, | |
1869 build_string ("Symbol's function definition is void")); | |
1870 | |
648 | 1871 Fput (Qcyclic_function_indirection, Qerror_conditions, |
1872 Fcons (Qcyclic_function_indirection, Fcons (Qerror, Qnil))); | |
1873 Fput (Qcyclic_function_indirection, Qerror_message, | |
1874 build_string ("Symbol's chain of function indirections contains a loop")); | |
1875 | |
298 | 1876 Fput (Qvoid_variable, Qerror_conditions, |
1877 Fcons (Qvoid_variable, Fcons (Qerror, Qnil))); | |
1878 Fput (Qvoid_variable, Qerror_message, | |
1879 build_string ("Symbol's value as variable is void")); | |
1880 | |
1881 Fput (Qsetting_constant, Qerror_conditions, | |
1882 Fcons (Qsetting_constant, Fcons (Qerror, Qnil))); | |
1883 Fput (Qsetting_constant, Qerror_message, | |
1884 build_string ("Attempt to set a constant symbol")); | |
1885 | |
1886 Fput (Qinvalid_read_syntax, Qerror_conditions, | |
1887 Fcons (Qinvalid_read_syntax, Fcons (Qerror, Qnil))); | |
1888 Fput (Qinvalid_read_syntax, Qerror_message, | |
1889 build_string ("Invalid read syntax")); | |
1890 | |
1891 Fput (Qinvalid_function, Qerror_conditions, | |
1892 Fcons (Qinvalid_function, Fcons (Qerror, Qnil))); | |
1893 Fput (Qinvalid_function, Qerror_message, | |
1894 build_string ("Invalid function")); | |
1895 | |
1896 Fput (Qwrong_number_of_arguments, Qerror_conditions, | |
1897 Fcons (Qwrong_number_of_arguments, Fcons (Qerror, Qnil))); | |
1898 Fput (Qwrong_number_of_arguments, Qerror_message, | |
1899 build_string ("Wrong number of arguments")); | |
1900 | |
1901 Fput (Qno_catch, Qerror_conditions, | |
1902 Fcons (Qno_catch, Fcons (Qerror, Qnil))); | |
1903 Fput (Qno_catch, Qerror_message, | |
1904 build_string ("No catch for tag")); | |
1905 | |
1906 Fput (Qend_of_file, Qerror_conditions, | |
1907 Fcons (Qend_of_file, Fcons (Qerror, Qnil))); | |
1908 Fput (Qend_of_file, Qerror_message, | |
1909 build_string ("End of file during parsing")); | |
1910 | |
1911 Fput (Qarith_error, Qerror_conditions, | |
1912 Fcons (Qarith_error, Fcons (Qerror, Qnil))); | |
1913 Fput (Qarith_error, Qerror_message, | |
1914 build_string ("Arithmetic error")); | |
1915 | |
1916 Fput (Qbeginning_of_buffer, Qerror_conditions, | |
1917 Fcons (Qbeginning_of_buffer, Fcons (Qerror, Qnil))); | |
1918 Fput (Qbeginning_of_buffer, Qerror_message, | |
1919 build_string ("Beginning of buffer")); | |
1920 | |
1921 Fput (Qend_of_buffer, Qerror_conditions, | |
1922 Fcons (Qend_of_buffer, Fcons (Qerror, Qnil))); | |
1923 Fput (Qend_of_buffer, Qerror_message, | |
1924 build_string ("End of buffer")); | |
1925 | |
1926 Fput (Qbuffer_read_only, Qerror_conditions, | |
1927 Fcons (Qbuffer_read_only, Fcons (Qerror, Qnil))); | |
1928 Fput (Qbuffer_read_only, Qerror_message, | |
1929 build_string ("Buffer is read-only")); | |
1930 | |
1931 staticpro (&Qnil); | |
1932 staticpro (&Qt); | |
1933 staticpro (&Qquote); | |
1934 staticpro (&Qlambda); | |
1935 staticpro (&Qsubr); | |
1936 staticpro (&Qunbound); | |
1937 staticpro (&Qerror_conditions); | |
1938 staticpro (&Qerror_message); | |
1939 staticpro (&Qtop_level); | |
1940 | |
1941 staticpro (&Qerror); | |
1942 staticpro (&Qquit); | |
1943 staticpro (&Qwrong_type_argument); | |
1944 staticpro (&Qargs_out_of_range); | |
1945 staticpro (&Qvoid_function); | |
648 | 1946 staticpro (&Qcyclic_function_indirection); |
298 | 1947 staticpro (&Qvoid_variable); |
1948 staticpro (&Qsetting_constant); | |
1949 staticpro (&Qinvalid_read_syntax); | |
1950 staticpro (&Qwrong_number_of_arguments); | |
1951 staticpro (&Qinvalid_function); | |
1952 staticpro (&Qno_catch); | |
1953 staticpro (&Qend_of_file); | |
1954 staticpro (&Qarith_error); | |
1955 staticpro (&Qbeginning_of_buffer); | |
1956 staticpro (&Qend_of_buffer); | |
1957 staticpro (&Qbuffer_read_only); | |
1958 | |
1959 staticpro (&Qlistp); | |
1960 staticpro (&Qconsp); | |
1961 staticpro (&Qsymbolp); | |
1962 staticpro (&Qintegerp); | |
1963 staticpro (&Qnatnump); | |
1964 staticpro (&Qstringp); | |
1965 staticpro (&Qarrayp); | |
1966 staticpro (&Qsequencep); | |
1967 staticpro (&Qbufferp); | |
1968 staticpro (&Qvectorp); | |
1969 staticpro (&Qchar_or_string_p); | |
1970 staticpro (&Qmarkerp); | |
1971 staticpro (&Qinteger_or_marker_p); | |
1972 #ifdef LISP_FLOAT_TYPE | |
1973 staticpro (&Qfloatp); | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1974 staticpro (&Qnumberp); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1975 staticpro (&Qnumber_or_marker_p); |
298 | 1976 #endif /* LISP_FLOAT_TYPE */ |
1977 | |
1978 staticpro (&Qboundp); | |
1979 staticpro (&Qfboundp); | |
1980 staticpro (&Qcdr); | |
1981 | |
1982 defsubr (&Seq); | |
1983 defsubr (&Snull); | |
1984 defsubr (&Slistp); | |
1985 defsubr (&Snlistp); | |
1986 defsubr (&Sconsp); | |
1987 defsubr (&Satom); | |
1988 defsubr (&Sintegerp); | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1989 defsubr (&Sinteger_or_marker_p); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1990 defsubr (&Snumberp); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1991 defsubr (&Snumber_or_marker_p); |
298 | 1992 #ifdef LISP_FLOAT_TYPE |
1993 defsubr (&Sfloatp); | |
1994 #endif /* LISP_FLOAT_TYPE */ | |
1995 defsubr (&Snatnump); | |
1996 defsubr (&Ssymbolp); | |
1997 defsubr (&Sstringp); | |
1998 defsubr (&Svectorp); | |
1999 defsubr (&Sarrayp); | |
2000 defsubr (&Ssequencep); | |
2001 defsubr (&Sbufferp); | |
2002 defsubr (&Smarkerp); | |
2003 defsubr (&Ssubrp); | |
2004 defsubr (&Scompiled_function_p); | |
2005 defsubr (&Schar_or_string_p); | |
2006 defsubr (&Scar); | |
2007 defsubr (&Scdr); | |
2008 defsubr (&Scar_safe); | |
2009 defsubr (&Scdr_safe); | |
2010 defsubr (&Ssetcar); | |
2011 defsubr (&Ssetcdr); | |
2012 defsubr (&Ssymbol_function); | |
648 | 2013 defsubr (&Sindirect_function); |
298 | 2014 defsubr (&Ssymbol_plist); |
2015 defsubr (&Ssymbol_name); | |
2016 defsubr (&Smakunbound); | |
2017 defsubr (&Sfmakunbound); | |
2018 defsubr (&Sboundp); | |
2019 defsubr (&Sfboundp); | |
2020 defsubr (&Sfset); | |
2021 defsubr (&Ssetplist); | |
2022 defsubr (&Ssymbol_value); | |
2023 defsubr (&Sset); | |
2024 defsubr (&Sdefault_boundp); | |
2025 defsubr (&Sdefault_value); | |
2026 defsubr (&Sset_default); | |
2027 defsubr (&Ssetq_default); | |
2028 defsubr (&Smake_variable_buffer_local); | |
2029 defsubr (&Smake_local_variable); | |
2030 defsubr (&Skill_local_variable); | |
2031 defsubr (&Saref); | |
2032 defsubr (&Saset); | |
2033 defsubr (&Sint_to_string); | |
2034 defsubr (&Sstring_to_int); | |
2035 defsubr (&Seqlsign); | |
2036 defsubr (&Slss); | |
2037 defsubr (&Sgtr); | |
2038 defsubr (&Sleq); | |
2039 defsubr (&Sgeq); | |
2040 defsubr (&Sneq); | |
2041 defsubr (&Szerop); | |
2042 defsubr (&Splus); | |
2043 defsubr (&Sminus); | |
2044 defsubr (&Stimes); | |
2045 defsubr (&Squo); | |
2046 defsubr (&Srem); | |
2047 defsubr (&Smax); | |
2048 defsubr (&Smin); | |
2049 defsubr (&Slogand); | |
2050 defsubr (&Slogior); | |
2051 defsubr (&Slogxor); | |
2052 defsubr (&Slsh); | |
2053 defsubr (&Sash); | |
2054 defsubr (&Sadd1); | |
2055 defsubr (&Ssub1); | |
2056 defsubr (&Slognot); | |
2057 } | |
2058 | |
490 | 2059 SIGTYPE |
298 | 2060 arith_error (signo) |
2061 int signo; | |
2062 { | |
2063 #ifdef USG | |
2064 /* USG systems forget handlers when they are used; | |
2065 must reestablish each time */ | |
2066 signal (signo, arith_error); | |
2067 #endif /* USG */ | |
2068 #ifdef VMS | |
2069 /* VMS systems are like USG. */ | |
2070 signal (signo, arith_error); | |
2071 #endif /* VMS */ | |
2072 #ifdef BSD4_1 | |
2073 sigrelse (SIGFPE); | |
2074 #else /* not BSD4_1 */ | |
638 | 2075 sigsetmask (SIGEMPTYMASK); |
298 | 2076 #endif /* not BSD4_1 */ |
2077 | |
2078 Fsignal (Qarith_error, Qnil); | |
2079 } | |
2080 | |
2081 init_data () | |
2082 { | |
2083 /* Don't do this if just dumping out. | |
2084 We don't want to call `signal' in this case | |
2085 so that we don't have trouble with dumping | |
2086 signal-delivering routines in an inconsistent state. */ | |
2087 #ifndef CANNOT_DUMP | |
2088 if (!initialized) | |
2089 return; | |
2090 #endif /* CANNOT_DUMP */ | |
2091 signal (SIGFPE, arith_error); | |
591 | 2092 |
298 | 2093 #ifdef uts |
2094 signal (SIGEMT, arith_error); | |
2095 #endif /* uts */ | |
2096 } |