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