0
|
1 /* Primitive operations on Lisp data types for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Mule 2.0, FSF 19.30. Some of FSF's data.c is in
|
|
23 XEmacs' symbols.c. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "bytecode.h"
|
|
32
|
|
33 #include "syssignal.h"
|
|
34 #ifdef LISP_FLOAT_TYPE
|
|
35 /* Need to define a differentiating symbol -- see sysfloat.h */
|
|
36 # define THIS_FILENAME data_c
|
|
37 # include "sysfloat.h"
|
|
38 #endif /* LISP_FLOAT_TYPE */
|
|
39
|
|
40 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
|
|
41 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
|
|
42 Lisp_Object Qsignal, Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range;
|
|
43 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
|
|
44 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
|
|
45 Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
|
|
46 Lisp_Object Qmalformed_list, Qmalformed_property_list;
|
|
47 Lisp_Object Qcircular_list, Qcircular_property_list;
|
|
48 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
|
|
49 Lisp_Object Qio_error, Qend_of_file;
|
|
50 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
|
|
51 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
|
|
52 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
|
|
53 Lisp_Object Qintegerp, Qnatnump, Qsymbolp, Qkeywordp, Qlistp, Qconsp, Qsubrp;
|
|
54 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qbufferp;
|
|
55 Lisp_Object Qcompiled_functionp;
|
|
56 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
|
|
57 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
|
|
58 Lisp_Object Qbit_vectorp, Qbitp;
|
|
59
|
|
60 /* Qstring, Qinteger, Qsymbol, Qvector defined in general.c */
|
|
61 Lisp_Object Qcons, Qkeyword;
|
|
62
|
|
63 Lisp_Object Qcdr;
|
|
64
|
|
65 Lisp_Object Qignore;
|
|
66
|
|
67 #ifdef LISP_FLOAT_TYPE
|
|
68 Lisp_Object Qfloatp;
|
|
69 #endif
|
|
70 Lisp_Object Qnumberp, Qnumber_or_marker_p, Qnumber_char_or_marker_p;
|
|
71
|
|
72 Lisp_Object Qweak_listp;
|
70
|
73
|
|
74 #ifdef DEBUG_XEMACS
|
|
75
|
|
76 int debug_issue_ebola_notices;
|
|
77
|
|
78 int debug_ebola_backtrace_length;
|
|
79
|
161
|
80 #if 0
|
|
81 /*#ifndef LRECORD_SYMBOL*/
|
159
|
82 #include "backtrace.h"
|
161
|
83 #endif
|
159
|
84
|
70
|
85 int
|
|
86 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
|
|
87 {
|
|
88 if (((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1)))
|
|
89 && (debug_issue_ebola_notices >= 2
|
207
|
90 || XCHAR_OR_INT (obj1) == XCHAR_OR_INT (obj2)))
|
70
|
91 {
|
108
|
92 stderr_out("Comparison between integer and character is constant nil (");
|
70
|
93 Fprinc (obj1, Qexternal_debugging_output);
|
|
94 stderr_out (" and ");
|
|
95 Fprinc (obj2, Qexternal_debugging_output);
|
|
96 stderr_out (")\n");
|
|
97 debug_short_backtrace (debug_ebola_backtrace_length);
|
|
98 }
|
|
99 return EQ (obj1, obj2);
|
|
100 }
|
|
101
|
|
102 #endif /* DEBUG_XEMACS */
|
|
103
|
|
104
|
0
|
105
|
|
106 Lisp_Object
|
|
107 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
108 {
|
|
109 /* This function can GC */
|
|
110 REGISTER Lisp_Object tem;
|
|
111 do
|
|
112 {
|
|
113 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
|
|
114 tem = call1 (predicate, value);
|
|
115 }
|
|
116 while (NILP (tem));
|
|
117 return value;
|
|
118 }
|
|
119
|
|
120 DOESNT_RETURN
|
|
121 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
122 {
|
|
123 signal_error (Qwrong_type_argument, list2 (predicate, value));
|
|
124 }
|
|
125
|
20
|
126 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
|
0
|
127 Signal an error until the correct type value is given by the user.
|
|
128 This function loops, signalling a continuable `wrong-type-argument' error
|
|
129 with PREDICATE and VALUE as the data associated with the error and then
|
|
130 calling PREDICATE on the returned value, until the value gotten satisfies
|
|
131 PREDICATE. At that point, the gotten value is returned.
|
20
|
132 */
|
|
133 (predicate, value))
|
0
|
134 {
|
|
135 return wrong_type_argument (predicate, value);
|
|
136 }
|
|
137
|
|
138 DOESNT_RETURN
|
|
139 pure_write_error (void)
|
|
140 {
|
|
141 error ("Attempt to modify read-only object");
|
|
142 }
|
|
143
|
|
144 DOESNT_RETURN
|
|
145 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
|
|
146 {
|
|
147 signal_error (Qargs_out_of_range, list2 (a1, a2));
|
|
148 }
|
|
149
|
|
150 DOESNT_RETURN
|
|
151 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
|
|
152 {
|
|
153 signal_error (Qargs_out_of_range, list3 (a1, a2, a3));
|
|
154 }
|
|
155
|
|
156 void
|
|
157 check_int_range (int val, int min, int max)
|
|
158 {
|
|
159 if (val < min || val > max)
|
|
160 args_out_of_range_3 (make_int (val), make_int (min),
|
|
161 make_int (max));
|
|
162 }
|
|
163
|
|
164 #ifndef make_int
|
|
165 Lisp_Object
|
|
166 make_int (EMACS_INT num)
|
|
167 {
|
|
168 Lisp_Object val;
|
207
|
169 #ifdef USE_MINIMAL_TAGBITS
|
|
170 XSETINT(val, num);
|
|
171 #else
|
0
|
172 /* Don't use XSETINT here -- it's defined in terms of make_int (). */
|
185
|
173 XSETOBJ (val, Lisp_Type_Int, num);
|
207
|
174 #endif
|
0
|
175 return val;
|
|
176 }
|
|
177 #endif /* ! defined (make_int) */
|
|
178
|
|
179 /* On some machines, XINT needs a temporary location.
|
|
180 Here it is, in case it is needed. */
|
|
181
|
|
182 EMACS_INT sign_extend_temp;
|
|
183
|
|
184 /* On a few machines, XINT can only be done by calling this. */
|
|
185 /* XEmacs: only used by m/convex.h */
|
|
186 int sign_extend_lisp_int (EMACS_INT num);
|
|
187 int
|
|
188 sign_extend_lisp_int (EMACS_INT num)
|
|
189 {
|
|
190 if (num & (1L << (VALBITS - 1)))
|
|
191 return num | ((-1L) << VALBITS);
|
|
192 else
|
|
193 return num & ((1L << VALBITS) - 1);
|
|
194 }
|
|
195
|
|
196 /* characters do not need to sign extend so there's no need for special
|
|
197 futzing like with ints. */
|
207
|
198 #ifndef make_char
|
0
|
199 Lisp_Object
|
|
200 make_char (Emchar num)
|
|
201 {
|
16
|
202 Lisp_Object val;
|
207
|
203 #ifdef USE_MINIMAL_TAGBITS
|
|
204 XSETCHAR (val, num);
|
|
205 #else
|
185
|
206 XSETOBJ (val, Lisp_Type_Char, num);
|
207
|
207 #endif
|
16
|
208 return val;
|
0
|
209 }
|
207
|
210 #endif /* ! make_char */
|
0
|
211
|
|
212 /* Data type predicates */
|
|
213
|
20
|
214 DEFUN ("eq", Feq, 2, 2, 0, /*
|
0
|
215 T if the two args are the same Lisp object.
|
20
|
216 */
|
|
217 (obj1, obj2))
|
0
|
218 {
|
70
|
219 return EQ_WITH_EBOLA_NOTICE (obj1, obj2) ? Qt : Qnil;
|
|
220 }
|
|
221
|
|
222 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
|
|
223 T if the two args are (in most cases) the same Lisp object.
|
|
224
|
|
225 Special kludge: A character is considered `old-eq' to its equivalent integer
|
|
226 even though they are not the same object and are in fact of different
|
|
227 types. This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
|
|
228 preserve byte-code compatibility with v19. This kludge is known as the
|
104
|
229 \"char-to-int confoundance disease\" and appears in a number of other
|
70
|
230 functions with `old-foo' equivalents.
|
|
231
|
|
232 Do not use this function!
|
|
233 */
|
|
234 (obj1, obj2))
|
|
235 {
|
|
236 /* The miscreant responsible for this blasphemy is known as
|
|
237 Richard M. Stallman, and he will burn in hell for it. */
|
|
238 return HACKEQ_UNSAFE (obj1, obj2) ? Qt : Qnil;
|
0
|
239 }
|
|
240
|
20
|
241 DEFUN ("null", Fnull, 1, 1, 0, /*
|
0
|
242 T if OBJECT is nil.
|
20
|
243 */
|
|
244 (object))
|
0
|
245 {
|
16
|
246 return NILP (object) ? Qt : Qnil;
|
0
|
247 }
|
|
248
|
20
|
249 DEFUN ("consp", Fconsp, 1, 1, 0, /*
|
0
|
250 T if OBJECT is a cons cell.
|
20
|
251 */
|
|
252 (object))
|
0
|
253 {
|
16
|
254 return CONSP (object) ? Qt : Qnil;
|
0
|
255 }
|
|
256
|
20
|
257 DEFUN ("atom", Fatom, 1, 1, 0, /*
|
0
|
258 T if OBJECT is not a cons cell. This includes nil.
|
20
|
259 */
|
|
260 (object))
|
0
|
261 {
|
16
|
262 return CONSP (object) ? Qnil : Qt;
|
0
|
263 }
|
|
264
|
20
|
265 DEFUN ("listp", Flistp, 1, 1, 0, /*
|
0
|
266 T if OBJECT is a list. This includes nil.
|
20
|
267 */
|
|
268 (object))
|
0
|
269 {
|
173
|
270 return CONSP (object) || NILP (object) ? Qt : Qnil;
|
0
|
271 }
|
|
272
|
20
|
273 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
|
0
|
274 T if OBJECT is not a list. Lists include nil.
|
20
|
275 */
|
|
276 (object))
|
0
|
277 {
|
173
|
278 return CONSP (object) || NILP (object) ? Qnil : Qt;
|
0
|
279 }
|
|
280
|
20
|
281 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
|
0
|
282 T if OBJECT is a symbol.
|
20
|
283 */
|
|
284 (object))
|
0
|
285 {
|
16
|
286 return SYMBOLP (object) ? Qt : Qnil;
|
0
|
287 }
|
|
288
|
20
|
289 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
|
0
|
290 T if OBJECT is a keyword.
|
20
|
291 */
|
|
292 (object))
|
0
|
293 {
|
16
|
294 return KEYWORDP (object) ? Qt : Qnil;
|
0
|
295 }
|
|
296
|
20
|
297 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
|
0
|
298 T if OBJECT is a vector.
|
20
|
299 */
|
|
300 (object))
|
0
|
301 {
|
16
|
302 return VECTORP (object) ? Qt : Qnil;
|
0
|
303 }
|
|
304
|
20
|
305 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
|
0
|
306 T if OBJECT is a bit vector.
|
20
|
307 */
|
|
308 (object))
|
0
|
309 {
|
16
|
310 return BIT_VECTORP (object) ? Qt : Qnil;
|
0
|
311 }
|
|
312
|
20
|
313 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
|
0
|
314 T if OBJECT is a string.
|
20
|
315 */
|
|
316 (object))
|
0
|
317 {
|
16
|
318 return STRINGP (object) ? Qt : Qnil;
|
0
|
319 }
|
|
320
|
20
|
321 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
|
0
|
322 T if OBJECT is an array (string, vector, or bit vector).
|
20
|
323 */
|
|
324 (object))
|
0
|
325 {
|
16
|
326 return (VECTORP (object) ||
|
|
327 STRINGP (object) ||
|
|
328 BIT_VECTORP (object))
|
|
329 ? Qt : Qnil;
|
0
|
330 }
|
|
331
|
20
|
332 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
|
0
|
333 T if OBJECT is a sequence (list or array).
|
20
|
334 */
|
|
335 (object))
|
0
|
336 {
|
16
|
337 return (CONSP (object) ||
|
|
338 NILP (object) ||
|
|
339 VECTORP (object) ||
|
|
340 STRINGP (object) ||
|
|
341 BIT_VECTORP (object))
|
|
342 ? Qt : Qnil;
|
0
|
343 }
|
|
344
|
20
|
345 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
|
0
|
346 T if OBJECT is a marker (editor pointer).
|
20
|
347 */
|
|
348 (object))
|
0
|
349 {
|
16
|
350 return MARKERP (object) ? Qt : Qnil;
|
0
|
351 }
|
|
352
|
20
|
353 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
|
0
|
354 T if OBJECT is a built-in function.
|
20
|
355 */
|
|
356 (object))
|
0
|
357 {
|
16
|
358 return SUBRP (object) ? Qt : Qnil;
|
0
|
359 }
|
|
360
|
20
|
361 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
|
0
|
362 Return minimum number of args built-in function SUBR may be called with.
|
20
|
363 */
|
|
364 (subr))
|
0
|
365 {
|
|
366 CHECK_SUBR (subr);
|
|
367 return make_int (XSUBR (subr)->min_args);
|
|
368 }
|
|
369
|
20
|
370 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
|
0
|
371 Return maximum number of args built-in function SUBR may be called with,
|
16
|
372 or nil if it takes an arbitrary number of arguments or is a special form.
|
20
|
373 */
|
|
374 (subr))
|
0
|
375 {
|
|
376 int nargs;
|
|
377 CHECK_SUBR (subr);
|
|
378 nargs = XSUBR (subr)->max_args;
|
|
379 if (nargs == MANY || nargs == UNEVALLED)
|
|
380 return Qnil;
|
|
381 else
|
|
382 return make_int (nargs);
|
|
383 }
|
|
384
|
209
|
385 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
|
|
386 Return the interactive spec of the subr object, or nil.
|
|
387 If non-nil, the return value will be a list whose first element is
|
|
388 `interactive' and whose second element is the interactive spec.
|
|
389 */
|
|
390 (subr))
|
|
391 {
|
|
392 CONST char *prompt;
|
|
393 CHECK_SUBR (subr);
|
|
394 prompt = XSUBR (subr)->prompt;
|
|
395 return prompt ? list2 (Qinteractive, build_string (prompt)) : Qnil;
|
|
396 }
|
|
397
|
20
|
398 DEFUN ("compiled-function-p", Fcompiled_function_p, 1, 1, 0, /*
|
0
|
399 t if OBJECT is a byte-compiled function object.
|
20
|
400 */
|
|
401 (object))
|
0
|
402 {
|
16
|
403 return COMPILED_FUNCTIONP (object) ? Qt : Qnil;
|
0
|
404 }
|
|
405
|
|
406
|
20
|
407 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
|
0
|
408 t if OBJECT is a character.
|
110
|
409 Unlike in XEmacs v19 and Emacs, a character is its own primitive type.
|
70
|
410 Any character can be converted into an equivalent integer using
|
104
|
411 `char-to-int'. To convert the other way, use `int-to-char'; however,
|
70
|
412 only some integers can be converted into characters. Such an integer
|
110
|
413 is called a `char-int'; see `char-int-p'.
|
70
|
414
|
|
415 Some functions that work on integers (e.g. the comparison functions
|
|
416 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
|
|
417 accept characters and implicitly convert them into integers. In
|
|
418 general, functions that work on characters also accept char-ints and
|
|
419 implicitly convert them into characters. WARNING: Neither of these
|
|
420 behaviors is very desirable, and they are maintained for backward
|
|
421 compatibility with old E-Lisp programs that confounded characters and
|
|
422 integers willy-nilly. These behaviors may change in the future; therefore,
|
|
423 do not rely on them. Instead, use the character-specific functions such
|
|
424 as `char='.
|
20
|
425 */
|
|
426 (object))
|
0
|
427 {
|
16
|
428 return CHARP (object) ? Qt : Qnil;
|
0
|
429 }
|
|
430
|
104
|
431 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
|
70
|
432 Convert a character into an equivalent integer.
|
|
433 The resulting integer will always be non-negative. The integers in
|
|
434 the range 0 - 255 map to characters as follows:
|
|
435
|
|
436 0 - 31 Control set 0
|
|
437 32 - 127 ASCII
|
|
438 128 - 159 Control set 1
|
|
439 160 - 255 Right half of ISO-8859-1
|
|
440
|
|
441 If support for Mule does not exist, these are the only valid character
|
|
442 values. When Mule support exists, the values assigned to other characters
|
|
443 may vary depending on the particular version of XEmacs, the order in which
|
|
444 character sets were loaded, etc., and you should not depend on them.
|
|
445 */
|
|
446 (ch))
|
|
447 {
|
|
448 CHECK_CHAR (ch);
|
|
449 return make_int (XCHAR (ch));
|
|
450 }
|
|
451
|
104
|
452 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
|
70
|
453 Convert an integer into the equivalent character.
|
|
454 Not all integers correspond to valid characters; use `char-int-p' to
|
|
455 determine whether this is the case. If the integer cannot be converted,
|
|
456 nil is returned.
|
|
457 */
|
|
458 (integer))
|
|
459 {
|
|
460 CHECK_INT (integer);
|
|
461 if (CHAR_INTP (integer))
|
|
462 return make_char (XINT (integer));
|
|
463 else
|
|
464 return Qnil;
|
|
465 }
|
|
466
|
|
467 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
|
|
468 t if OBJECT is an integer that can be converted into a character.
|
104
|
469 See `char-to-int'.
|
70
|
470 */
|
|
471 (object))
|
|
472 {
|
|
473 return CHAR_INTP (object) ? Qt : Qnil;
|
|
474 }
|
|
475
|
|
476 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
|
|
477 t if OBJECT is a character or an integer that can be converted into one.
|
|
478 */
|
|
479 (object))
|
|
480 {
|
|
481 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
|
|
482 }
|
|
483
|
20
|
484 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
|
70
|
485 t if OBJECT is a character (or a char-int) or a string.
|
|
486 It is semi-hateful that we allow a char-int here, as it goes against
|
|
487 the name of this function, but it makes the most sense considering the
|
|
488 other steps we take to maintain compatibility with the old character/integer
|
|
489 confoundedness in older versions of E-Lisp.
|
20
|
490 */
|
|
491 (object))
|
0
|
492 {
|
16
|
493 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
|
0
|
494 }
|
|
495
|
20
|
496 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
|
0
|
497 t if OBJECT is an integer.
|
20
|
498 */
|
|
499 (object))
|
0
|
500 {
|
16
|
501 return INTP (object) ? Qt : Qnil;
|
0
|
502 }
|
|
503
|
20
|
504 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
|
0
|
505 t if OBJECT is an integer or a marker (editor pointer).
|
20
|
506 */
|
|
507 (object))
|
0
|
508 {
|
16
|
509 return INTP (object) || MARKERP (object) ? Qt : Qnil;
|
0
|
510 }
|
|
511
|
70
|
512 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
|
|
513 t if OBJECT is an integer or a character.
|
|
514 */
|
|
515 (object))
|
|
516 {
|
|
517 return INTP (object) || CHARP (object) ? Qt : Qnil;
|
|
518 }
|
|
519
|
|
520 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
|
|
521 t if OBJECT is an integer, character or a marker (editor pointer).
|
|
522 */
|
|
523 (object))
|
|
524 {
|
|
525 return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
|
|
526 }
|
|
527
|
20
|
528 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
|
0
|
529 t if OBJECT is a nonnegative integer.
|
20
|
530 */
|
|
531 (object))
|
0
|
532 {
|
16
|
533 return NATNUMP (object) ? Qt : Qnil;
|
0
|
534 }
|
|
535
|
20
|
536 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
|
0
|
537 t if OBJECT is a bit (0 or 1).
|
20
|
538 */
|
|
539 (object))
|
0
|
540 {
|
16
|
541 return BITP (object) ? Qt : Qnil;
|
0
|
542 }
|
|
543
|
20
|
544 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
|
0
|
545 t if OBJECT is a number (floating point or integer).
|
20
|
546 */
|
|
547 (object))
|
0
|
548 {
|
16
|
549 return INT_OR_FLOATP (object) ? Qt : Qnil;
|
0
|
550 }
|
|
551
|
20
|
552 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
|
0
|
553 t if OBJECT is a number or a marker.
|
20
|
554 */
|
|
555 (object))
|
0
|
556 {
|
16
|
557 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
|
0
|
558 }
|
|
559
|
70
|
560 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
|
|
561 t if OBJECT is a number, character or a marker.
|
|
562 */
|
|
563 (object))
|
|
564 {
|
|
565 return (INT_OR_FLOATP (object) ||
|
|
566 CHARP (object) ||
|
|
567 MARKERP (object))
|
|
568 ? Qt : Qnil;
|
|
569 }
|
|
570
|
0
|
571 #ifdef LISP_FLOAT_TYPE
|
20
|
572 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
|
0
|
573 t if OBJECT is a floating point number.
|
20
|
574 */
|
|
575 (object))
|
0
|
576 {
|
16
|
577 return FLOATP (object) ? Qt : Qnil;
|
0
|
578 }
|
|
579 #endif /* LISP_FLOAT_TYPE */
|
|
580
|
20
|
581 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
|
0
|
582 Return a symbol representing the type of OBJECT.
|
20
|
583 */
|
|
584 (object))
|
0
|
585 {
|
16
|
586 if (CONSP (object)) return Qcons;
|
|
587 if (SYMBOLP (object)) return Qsymbol;
|
|
588 if (KEYWORDP (object)) return Qkeyword;
|
|
589 if (INTP (object)) return Qinteger;
|
70
|
590 if (CHARP (object)) return Qcharacter;
|
16
|
591 if (STRINGP (object)) return Qstring;
|
|
592 if (VECTORP (object)) return Qvector;
|
173
|
593
|
0
|
594 assert (LRECORDP (object));
|
211
|
595 return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
|
0
|
596 }
|
|
597
|
|
598
|
|
599 /* Extract and set components of lists */
|
|
600
|
20
|
601 DEFUN ("car", Fcar, 1, 1, 0, /*
|
0
|
602 Return the car of LIST. If arg is nil, return nil.
|
|
603 Error if arg is not nil and not a cons cell. See also `car-safe'.
|
20
|
604 */
|
|
605 (list))
|
0
|
606 {
|
|
607 while (1)
|
|
608 {
|
|
609 if (CONSP (list))
|
|
610 return XCAR (list);
|
|
611 else if (NILP (list))
|
|
612 return Qnil;
|
|
613 else
|
|
614 list = wrong_type_argument (Qconsp, list);
|
|
615 }
|
|
616 }
|
|
617
|
20
|
618 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
|
0
|
619 Return the car of OBJECT if it is a cons cell, or else nil.
|
20
|
620 */
|
|
621 (object))
|
0
|
622 {
|
16
|
623 return CONSP (object) ? XCAR (object) : Qnil;
|
0
|
624 }
|
|
625
|
20
|
626 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
|
0
|
627 Return the cdr of LIST. If arg is nil, return nil.
|
|
628 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
|
20
|
629 */
|
|
630 (list))
|
0
|
631 {
|
|
632 while (1)
|
|
633 {
|
|
634 if (CONSP (list))
|
|
635 return XCDR (list);
|
|
636 else if (NILP (list))
|
|
637 return Qnil;
|
|
638 else
|
|
639 list = wrong_type_argument (Qconsp, list);
|
|
640 }
|
|
641 }
|
|
642
|
20
|
643 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
|
0
|
644 Return the cdr of OBJECT if it is a cons cell, or else nil.
|
20
|
645 */
|
|
646 (object))
|
0
|
647 {
|
16
|
648 return CONSP (object) ? XCDR (object) : Qnil;
|
0
|
649 }
|
|
650
|
20
|
651 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
|
0
|
652 Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.
|
20
|
653 */
|
|
654 (conscell, newcar))
|
0
|
655 {
|
|
656 if (!CONSP (conscell))
|
|
657 conscell = wrong_type_argument (Qconsp, conscell);
|
|
658
|
|
659 CHECK_IMPURE (conscell);
|
|
660 XCAR (conscell) = newcar;
|
|
661 return newcar;
|
|
662 }
|
|
663
|
20
|
664 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
|
0
|
665 Set the cdr of CONSCELL to be NEWCDR. Returns NEWCDR.
|
20
|
666 */
|
|
667 (conscell, newcdr))
|
0
|
668 {
|
|
669 if (!CONSP (conscell))
|
|
670 conscell = wrong_type_argument (Qconsp, conscell);
|
|
671
|
|
672 CHECK_IMPURE (conscell);
|
|
673 XCDR (conscell) = newcdr;
|
|
674 return newcdr;
|
|
675 }
|
|
676
|
|
677 /* Find the function at the end of a chain of symbol function indirections. */
|
|
678
|
|
679 /* If OBJECT is a symbol, find the end of its function chain and
|
|
680 return the value found there. If OBJECT is not a symbol, just
|
|
681 return it. If there is a cycle in the function chain, signal a
|
|
682 cyclic-function-indirection error.
|
|
683
|
|
684 This is like Findirect_function, except that it doesn't signal an
|
|
685 error if the chain ends up unbound. */
|
|
686 Lisp_Object
|
|
687 indirect_function (Lisp_Object object, int errorp)
|
|
688 {
|
173
|
689 Lisp_Object tortoise = object;
|
16
|
690 Lisp_Object hare = object;
|
0
|
691
|
|
692 for (;;)
|
|
693 {
|
|
694 if (!SYMBOLP (hare) || UNBOUNDP (hare))
|
|
695 break;
|
|
696 hare = XSYMBOL (hare)->function;
|
|
697 if (!SYMBOLP (hare) || UNBOUNDP (hare))
|
|
698 break;
|
|
699 hare = XSYMBOL (hare)->function;
|
|
700
|
|
701 tortoise = XSYMBOL (tortoise)->function;
|
|
702
|
|
703 if (EQ (hare, tortoise))
|
173
|
704 return Fsignal (Qcyclic_function_indirection, list1 (object));
|
0
|
705 }
|
|
706
|
|
707 if (UNBOUNDP (hare) && errorp)
|
|
708 return Fsignal (Qvoid_function, list1 (object));
|
|
709 return hare;
|
|
710 }
|
|
711
|
20
|
712 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
|
0
|
713 Return the function at the end of OBJECT's function chain.
|
|
714 If OBJECT is a symbol, follow all function indirections and return
|
|
715 the final function binding.
|
|
716 If OBJECT is not a symbol, just return it.
|
|
717 Signal a void-function error if the final symbol is unbound.
|
|
718 Signal a cyclic-function-indirection error if there is a loop in the
|
|
719 function chain of symbols.
|
20
|
720 */
|
|
721 (object))
|
0
|
722 {
|
|
723 return indirect_function (object, 1);
|
|
724 }
|
|
725
|
|
726 /* Extract and set vector and string elements */
|
|
727
|
20
|
728 DEFUN ("aref", Faref, 2, 2, 0, /*
|
0
|
729 Return the element of ARRAY at index INDEX.
|
|
730 ARRAY may be a vector, bit vector, string, or byte-code object.
|
|
731 IDX starts at 0.
|
20
|
732 */
|
|
733 (array, idx))
|
0
|
734 {
|
|
735 int idxval;
|
|
736
|
|
737 retry:
|
|
738 CHECK_INT_COERCE_CHAR (idx); /* yuck! */
|
|
739 idxval = XINT (idx);
|
|
740 if (idxval < 0)
|
|
741 {
|
|
742 lose:
|
|
743 args_out_of_range (array, idx);
|
|
744 }
|
|
745 if (VECTORP (array))
|
|
746 {
|
173
|
747 if (idxval >= XVECTOR_LENGTH (array)) goto lose;
|
|
748 return XVECTOR_DATA (array)[idxval];
|
0
|
749 }
|
|
750 else if (BIT_VECTORP (array))
|
|
751 {
|
|
752 if (idxval >= bit_vector_length (XBIT_VECTOR (array))) goto lose;
|
|
753 return make_int (bit_vector_bit (XBIT_VECTOR (array), idxval));
|
|
754 }
|
|
755 else if (STRINGP (array))
|
|
756 {
|
|
757 if (idxval >= string_char_length (XSTRING (array))) goto lose;
|
173
|
758 return make_char (string_char (XSTRING (array), idxval));
|
0
|
759 }
|
|
760 #ifdef LOSING_BYTECODE
|
|
761 else if (COMPILED_FUNCTIONP (array))
|
|
762 {
|
|
763 /* Weird, gross compatibility kludge */
|
173
|
764 return Felt (array, idx);
|
0
|
765 }
|
|
766 #endif
|
|
767 else
|
|
768 {
|
|
769 check_losing_bytecode ("aref", array);
|
|
770 array = wrong_type_argument (Qarrayp, array);
|
|
771 goto retry;
|
|
772 }
|
|
773 }
|
|
774
|
20
|
775 DEFUN ("aset", Faset, 3, 3, 0, /*
|
0
|
776 Store into the element of ARRAY at index IDX the value NEWVAL.
|
|
777 ARRAY may be a vector, bit vector, or string. IDX starts at 0.
|
20
|
778 */
|
|
779 (array, idx, newval))
|
0
|
780 {
|
|
781 int idxval;
|
|
782
|
|
783 CHECK_INT_COERCE_CHAR (idx); /* yuck! */
|
|
784 if (!VECTORP (array) && !BIT_VECTORP (array) && !STRINGP (array))
|
|
785 array = wrong_type_argument (Qarrayp, array);
|
|
786
|
|
787 idxval = XINT (idx);
|
|
788 if (idxval < 0)
|
|
789 {
|
|
790 lose:
|
|
791 args_out_of_range (array, idx);
|
|
792 }
|
|
793 CHECK_IMPURE (array);
|
|
794
|
|
795 if (VECTORP (array))
|
|
796 {
|
173
|
797 if (idxval >= XVECTOR_LENGTH (array)) goto lose;
|
|
798 XVECTOR_DATA (array)[idxval] = newval;
|
0
|
799 }
|
|
800 else if (BIT_VECTORP (array))
|
|
801 {
|
|
802 if (idxval >= bit_vector_length (XBIT_VECTOR (array))) goto lose;
|
|
803 CHECK_BIT (newval);
|
|
804 set_bit_vector_bit (XBIT_VECTOR (array), idxval, !ZEROP (newval));
|
|
805 }
|
|
806 else /* string */
|
|
807 {
|
|
808 CHECK_CHAR_COERCE_INT (newval);
|
|
809 if (idxval >= string_char_length (XSTRING (array))) goto lose;
|
|
810 set_string_char (XSTRING (array), idxval, XCHAR (newval));
|
|
811 bump_string_modiff (array);
|
|
812 }
|
|
813
|
|
814 return newval;
|
|
815 }
|
|
816
|
|
817
|
|
818 /**********************************************************************/
|
|
819 /* Compiled-function objects */
|
|
820 /**********************************************************************/
|
|
821
|
|
822 /* The compiled_function->doc_and_interactive slot uses the minimal
|
|
823 number of conses, based on compiled_function->flags; it may take
|
|
824 any of the following forms:
|
|
825
|
|
826 doc
|
|
827 interactive
|
|
828 domain
|
|
829 (doc . interactive)
|
|
830 (doc . domain)
|
|
831 (interactive . domain)
|
|
832 (doc . (interactive . domain))
|
|
833 */
|
|
834
|
|
835 /* Caller must check flags.interactivep first */
|
|
836 Lisp_Object
|
|
837 compiled_function_interactive (struct Lisp_Compiled_Function *b)
|
|
838 {
|
|
839 assert (b->flags.interactivep);
|
|
840 if (b->flags.documentationp && b->flags.domainp)
|
173
|
841 return XCAR (XCDR (b->doc_and_interactive));
|
0
|
842 else if (b->flags.documentationp)
|
173
|
843 return XCDR (b->doc_and_interactive);
|
0
|
844 else if (b->flags.domainp)
|
173
|
845 return XCAR (b->doc_and_interactive);
|
0
|
846
|
|
847 /* if all else fails... */
|
173
|
848 return b->doc_and_interactive;
|
0
|
849 }
|
|
850
|
|
851 /* Caller need not check flags.documentationp first */
|
|
852 Lisp_Object
|
|
853 compiled_function_documentation (struct Lisp_Compiled_Function *b)
|
|
854 {
|
|
855 if (! b->flags.documentationp)
|
|
856 return Qnil;
|
|
857 else if (b->flags.interactivep && b->flags.domainp)
|
173
|
858 return XCAR (b->doc_and_interactive);
|
0
|
859 else if (b->flags.interactivep)
|
173
|
860 return XCAR (b->doc_and_interactive);
|
0
|
861 else if (b->flags.domainp)
|
173
|
862 return XCAR (b->doc_and_interactive);
|
0
|
863 else
|
173
|
864 return b->doc_and_interactive;
|
0
|
865 }
|
|
866
|
|
867 /* Caller need not check flags.domainp first */
|
|
868 Lisp_Object
|
|
869 compiled_function_domain (struct Lisp_Compiled_Function *b)
|
|
870 {
|
|
871 if (! b->flags.domainp)
|
|
872 return Qnil;
|
|
873 else if (b->flags.documentationp && b->flags.interactivep)
|
173
|
874 return XCDR (XCDR (b->doc_and_interactive));
|
0
|
875 else if (b->flags.documentationp)
|
173
|
876 return XCDR (b->doc_and_interactive);
|
0
|
877 else if (b->flags.interactivep)
|
173
|
878 return XCDR (b->doc_and_interactive);
|
0
|
879 else
|
173
|
880 return b->doc_and_interactive;
|
0
|
881 }
|
|
882
|
|
883 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
884
|
|
885 Lisp_Object
|
|
886 compiled_function_annotation (struct Lisp_Compiled_Function *b)
|
|
887 {
|
|
888 return b->annotated;
|
|
889 }
|
|
890
|
|
891 #endif
|
|
892
|
|
893 /* used only by Snarf-documentation; there must be doc already. */
|
|
894 void
|
|
895 set_compiled_function_documentation (struct Lisp_Compiled_Function *b,
|
|
896 Lisp_Object new)
|
|
897 {
|
|
898 assert (b->flags.documentationp);
|
|
899 assert (INTP (new) || STRINGP (new));
|
|
900
|
|
901 if (b->flags.interactivep && b->flags.domainp)
|
|
902 XCAR (b->doc_and_interactive) = new;
|
|
903 else if (b->flags.interactivep)
|
|
904 XCAR (b->doc_and_interactive) = new;
|
|
905 else if (b->flags.domainp)
|
|
906 XCAR (b->doc_and_interactive) = new;
|
|
907 else
|
|
908 b->doc_and_interactive = new;
|
|
909 }
|
|
910
|
20
|
911 DEFUN ("compiled-function-instructions", Fcompiled_function_instructions, 1, 1, 0, /*
|
0
|
912 Return the byte-opcode string of the compiled-function object.
|
20
|
913 */
|
|
914 (function))
|
0
|
915 {
|
|
916 CHECK_COMPILED_FUNCTION (function);
|
173
|
917 return XCOMPILED_FUNCTION (function)->bytecodes;
|
0
|
918 }
|
|
919
|
20
|
920 DEFUN ("compiled-function-constants", Fcompiled_function_constants, 1, 1, 0, /*
|
0
|
921 Return the constants vector of the compiled-function object.
|
20
|
922 */
|
|
923 (function))
|
0
|
924 {
|
|
925 CHECK_COMPILED_FUNCTION (function);
|
173
|
926 return XCOMPILED_FUNCTION (function)->constants;
|
0
|
927 }
|
|
928
|
20
|
929 DEFUN ("compiled-function-stack-depth", Fcompiled_function_stack_depth, 1, 1, 0, /*
|
0
|
930 Return the max stack depth of the compiled-function object.
|
20
|
931 */
|
|
932 (function))
|
0
|
933 {
|
|
934 CHECK_COMPILED_FUNCTION (function);
|
173
|
935 return make_int (XCOMPILED_FUNCTION (function)->maxdepth);
|
0
|
936 }
|
|
937
|
20
|
938 DEFUN ("compiled-function-arglist", Fcompiled_function_arglist, 1, 1, 0, /*
|
0
|
939 Return the argument list of the compiled-function object.
|
20
|
940 */
|
|
941 (function))
|
0
|
942 {
|
|
943 CHECK_COMPILED_FUNCTION (function);
|
173
|
944 return XCOMPILED_FUNCTION (function)->arglist;
|
0
|
945 }
|
|
946
|
20
|
947 DEFUN ("compiled-function-interactive", Fcompiled_function_interactive, 1, 1, 0, /*
|
0
|
948 Return the interactive spec of the compiled-function object, or nil.
|
|
949 If non-nil, the return value will be a list whose first element is
|
|
950 `interactive' and whose second element is the interactive spec.
|
20
|
951 */
|
|
952 (function))
|
0
|
953 {
|
|
954 CHECK_COMPILED_FUNCTION (function);
|
179
|
955 return XCOMPILED_FUNCTION (function)->flags.interactivep
|
|
956 ? list2 (Qinteractive,
|
|
957 compiled_function_interactive (XCOMPILED_FUNCTION (function)))
|
|
958 : Qnil;
|
0
|
959 }
|
|
960
|
20
|
961 DEFUN ("compiled-function-doc-string", Fcompiled_function_doc_string, 1, 1, 0, /*
|
0
|
962 Return the doc string of the compiled-function object, if available.
|
171
|
963 Functions that had their doc strings snarfed into the DOC file will have
|
|
964 an integer returned instead of a string.
|
20
|
965 */
|
|
966 (function))
|
0
|
967 {
|
|
968 CHECK_COMPILED_FUNCTION (function);
|
171
|
969 return compiled_function_documentation (XCOMPILED_FUNCTION (function));
|
0
|
970 }
|
|
971
|
|
972 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
973
|
233
|
974 /* Remove the `xx' if you wish to restore this feature */
|
|
975 xxDEFUN ("compiled-function-annotation", Fcompiled_function_annotation, 1, 1, 0, /*
|
0
|
976 Return the annotation of the compiled-function object, or nil.
|
|
977 The annotation is a piece of information indicating where this
|
|
978 compiled-function object came from. Generally this will be
|
|
979 a symbol naming a function; or a string naming a file, if the
|
|
980 compiled-function object was not defined in a function; or nil,
|
|
981 if the compiled-function object was not created as a result of
|
|
982 a `load'.
|
20
|
983 */
|
|
984 (function))
|
0
|
985 {
|
|
986 CHECK_COMPILED_FUNCTION (function);
|
173
|
987 return compiled_function_annotation (XCOMPILED_FUNCTION (function));
|
0
|
988 }
|
|
989
|
|
990 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
991
|
20
|
992 DEFUN ("compiled-function-domain", Fcompiled_function_domain, 1, 1, 0, /*
|
0
|
993 Return the domain of the compiled-function object, or nil.
|
|
994 This is only meaningful if I18N3 was enabled when emacs was compiled.
|
20
|
995 */
|
|
996 (function))
|
0
|
997 {
|
|
998 CHECK_COMPILED_FUNCTION (function);
|
179
|
999 return XCOMPILED_FUNCTION (function)->flags.domainp
|
|
1000 ? compiled_function_domain (XCOMPILED_FUNCTION (function))
|
|
1001 : Qnil;
|
0
|
1002 }
|
|
1003
|
|
1004
|
|
1005 /**********************************************************************/
|
|
1006 /* Arithmetic functions */
|
|
1007 /**********************************************************************/
|
|
1008
|
|
1009 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
|
|
1010
|
|
1011 static Lisp_Object
|
16
|
1012 arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison)
|
0
|
1013 {
|
|
1014 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num1);
|
|
1015 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num2);
|
|
1016
|
|
1017 #ifdef LISP_FLOAT_TYPE
|
|
1018 if (FLOATP (num1) || FLOATP (num2))
|
|
1019 {
|
16
|
1020 double f1 = (FLOATP (num1)) ? float_data (XFLOAT (num1)) : XINT (num1);
|
|
1021 double f2 = (FLOATP (num2)) ? float_data (XFLOAT (num2)) : XINT (num2);
|
0
|
1022
|
|
1023 switch (comparison)
|
16
|
1024 {
|
|
1025 case equal: return f1 == f2 ? Qt : Qnil;
|
|
1026 case notequal: return f1 != f2 ? Qt : Qnil;
|
|
1027 case less: return f1 < f2 ? Qt : Qnil;
|
|
1028 case less_or_equal: return f1 <= f2 ? Qt : Qnil;
|
|
1029 case grtr: return f1 > f2 ? Qt : Qnil;
|
|
1030 case grtr_or_equal: return f1 >= f2 ? Qt : Qnil;
|
|
1031 }
|
0
|
1032 }
|
|
1033 #endif /* LISP_FLOAT_TYPE */
|
173
|
1034
|
16
|
1035 switch (comparison)
|
0
|
1036 {
|
16
|
1037 case equal: return XINT (num1) == XINT (num2) ? Qt : Qnil;
|
|
1038 case notequal: return XINT (num1) != XINT (num2) ? Qt : Qnil;
|
|
1039 case less: return XINT (num1) < XINT (num2) ? Qt : Qnil;
|
|
1040 case less_or_equal: return XINT (num1) <= XINT (num2) ? Qt : Qnil;
|
|
1041 case grtr: return XINT (num1) > XINT (num2) ? Qt : Qnil;
|
|
1042 case grtr_or_equal: return XINT (num1) >= XINT (num2) ? Qt : Qnil;
|
|
1043 }
|
0
|
1044
|
|
1045 abort ();
|
|
1046 return Qnil; /* suppress compiler warning */
|
|
1047 }
|
|
1048
|
20
|
1049 DEFUN ("=", Feqlsign, 2, 2, 0, /*
|
70
|
1050 T if two args, both numbers, characters or markers, are equal.
|
20
|
1051 */
|
|
1052 (num1, num2))
|
0
|
1053 {
|
|
1054 return arithcompare (num1, num2, equal);
|
|
1055 }
|
|
1056
|
20
|
1057 DEFUN ("<", Flss, 2, 2, 0, /*
|
16
|
1058 T if first arg is less than second arg.
|
70
|
1059 Both must be numbers, characters or markers.
|
20
|
1060 */
|
|
1061 (num1, num2))
|
0
|
1062 {
|
|
1063 return arithcompare (num1, num2, less);
|
|
1064 }
|
|
1065
|
20
|
1066 DEFUN (">", Fgtr, 2, 2, 0, /*
|
16
|
1067 T if first arg is greater than second arg.
|
70
|
1068 Both must be numbers, characters or markers.
|
20
|
1069 */
|
|
1070 (num1, num2))
|
0
|
1071 {
|
|
1072 return arithcompare (num1, num2, grtr);
|
|
1073 }
|
|
1074
|
20
|
1075 DEFUN ("<=", Fleq, 2, 2, 0, /*
|
0
|
1076 T if first arg is less than or equal to second arg.
|
70
|
1077 Both must be numbers, characters or markers.
|
20
|
1078 */
|
|
1079 (num1, num2))
|
0
|
1080 {
|
|
1081 return arithcompare (num1, num2, less_or_equal);
|
|
1082 }
|
|
1083
|
20
|
1084 DEFUN (">=", Fgeq, 2, 2, 0, /*
|
0
|
1085 T if first arg is greater than or equal to second arg.
|
70
|
1086 Both must be numbers, characters or markers.
|
20
|
1087 */
|
|
1088 (num1, num2))
|
0
|
1089 {
|
|
1090 return arithcompare (num1, num2, grtr_or_equal);
|
|
1091 }
|
|
1092
|
20
|
1093 DEFUN ("/=", Fneq, 2, 2, 0, /*
|
16
|
1094 T if first arg is not equal to second arg.
|
70
|
1095 Both must be numbers, characters or markers.
|
20
|
1096 */
|
|
1097 (num1, num2))
|
0
|
1098 {
|
|
1099 return arithcompare (num1, num2, notequal);
|
|
1100 }
|
|
1101
|
70
|
1102 #if 0
|
|
1103 /* I tried implementing Common Lisp multi-arg comparison functions,
|
|
1104 but failed because the byte-compiler needs to be hacked as well. */
|
|
1105
|
|
1106 static Lisp_Object
|
|
1107 arithcompare_many (enum comparison comparison, int nargs, Lisp_Object *args)
|
|
1108 {
|
|
1109 REGISTER int argnum;
|
|
1110 for (argnum = 1; argnum < nargs; argnum++)
|
|
1111 if (EQ (arithcompare ( args[argnum-1], args[argnum], comparison), Qnil))
|
|
1112 return Qnil;
|
|
1113
|
|
1114 return Qt;
|
|
1115 }
|
|
1116
|
|
1117 xxxDEFUN ("=", Feqlsign, 1, MANY, 0, /*
|
|
1118 T if all the arguments are equal.
|
|
1119 The arguments may be numbers, characters or markers.
|
|
1120 */
|
|
1121 (int nargs, Lisp_Object *args))
|
|
1122 {
|
|
1123 return arithcompare (equal, nargs, args);
|
|
1124 }
|
|
1125
|
|
1126 xxxDEFUN ("<", Flss, 1, MANY, 0, /*
|
|
1127 T if the sequence of arguments is monotonically increasing.
|
|
1128 The arguments may be numbers, characters or markers.
|
|
1129 */
|
|
1130 (int nargs, Lisp_Object *args))
|
|
1131 {
|
|
1132 return arithcompare (less, nargs, args);
|
|
1133 }
|
|
1134
|
|
1135 xxxDEFUN (">", Fgtr, 1, MANY, 0, /*
|
|
1136 T if the sequence of arguments is monotonically decreasing.
|
|
1137 The arguments may be numbers, characters or markers.
|
|
1138 */
|
|
1139 (int nargs, Lisp_Object *args))
|
|
1140 {
|
|
1141 return arithcompare (grtr, nargs, args);
|
|
1142 }
|
|
1143
|
|
1144 xxxDEFUN ("<=", Fleq, 1, MANY, 0, /*
|
|
1145 T if the sequence of arguments is monotonically nondecreasing.
|
|
1146 The arguments may be numbers, characters or markers.
|
|
1147 */
|
|
1148 (int nargs, Lisp_Object *args))
|
|
1149 {
|
|
1150 return arithcompare (less_or_equal, nargs, args);
|
|
1151 }
|
|
1152
|
|
1153 xxxDEFUN (">=", Fgeq, 1, MANY, 0, /*
|
|
1154 T if the sequence of arguments is monotonically nonincreasing.
|
|
1155 The arguments may be numbers, characters or markers.
|
|
1156 */
|
|
1157 (int nargs, Lisp_Object *args))
|
|
1158 {
|
|
1159 return arithcompare_many (grtr_or_equal, nargs, args);
|
|
1160 }
|
|
1161
|
|
1162 xxxDEFUN ("/=", Fneq, 1, MANY, 0, /*
|
|
1163 T if the sequence of arguments is monotonically increasing.
|
|
1164 The arguments may be numbers, characters or markers.
|
|
1165 */
|
|
1166 (int nargs, Lisp_Object *args))
|
|
1167 {
|
|
1168 return arithcompare_many (notequal, nargs, args);
|
|
1169 }
|
|
1170 #endif /* 0 - disabled for now */
|
|
1171
|
20
|
1172 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
|
0
|
1173 T if NUMBER is zero.
|
20
|
1174 */
|
|
1175 (number))
|
0
|
1176 {
|
|
1177 CHECK_INT_OR_FLOAT (number);
|
|
1178
|
|
1179 #ifdef LISP_FLOAT_TYPE
|
|
1180 if (FLOATP (number))
|
173
|
1181 return float_data (XFLOAT (number)) == 0.0 ? Qt : Qnil;
|
0
|
1182 #endif /* LISP_FLOAT_TYPE */
|
|
1183
|
173
|
1184 return XINT (number) == 0 ? Qt : Qnil;
|
0
|
1185 }
|
|
1186
|
|
1187 /* Convert between a 32-bit value and a cons of two 16-bit values.
|
|
1188 This is used to pass 32-bit integers to and from the user.
|
|
1189 Use time_to_lisp() and lisp_to_time() for time values.
|
|
1190
|
|
1191 If you're thinking of using this to store a pointer into a Lisp Object
|
|
1192 for internal purposes (such as when calling record_unwind_protect()),
|
|
1193 try using make_opaque_ptr()/get_opaque_ptr() instead. */
|
|
1194 Lisp_Object
|
|
1195 word_to_lisp (unsigned int item)
|
|
1196 {
|
|
1197 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
|
|
1198 }
|
|
1199
|
|
1200 unsigned int
|
|
1201 lisp_to_word (Lisp_Object item)
|
|
1202 {
|
|
1203 if (INTP (item))
|
|
1204 return XINT (item);
|
|
1205 else
|
|
1206 {
|
|
1207 Lisp_Object top = Fcar (item);
|
|
1208 Lisp_Object bot = Fcdr (item);
|
|
1209 CHECK_INT (top);
|
|
1210 CHECK_INT (bot);
|
|
1211 return (XINT (top) << 16) | (XINT (bot) & 0xffff);
|
|
1212 }
|
|
1213 }
|
|
1214
|
|
1215
|
20
|
1216 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
|
0
|
1217 Convert NUM to a string by printing it in decimal.
|
|
1218 Uses a minus sign if negative.
|
|
1219 NUM may be an integer or a floating point number.
|
20
|
1220 */
|
|
1221 (num))
|
0
|
1222 {
|
|
1223 char buffer[VALBITS];
|
|
1224
|
|
1225 CHECK_INT_OR_FLOAT (num);
|
|
1226
|
|
1227 #ifdef LISP_FLOAT_TYPE
|
|
1228 if (FLOATP (num))
|
|
1229 {
|
|
1230 char pigbuf[350]; /* see comments in float_to_string */
|
|
1231
|
|
1232 float_to_string (pigbuf, float_data (XFLOAT (num)));
|
173
|
1233 return build_string (pigbuf);
|
0
|
1234 }
|
|
1235 #endif /* LISP_FLOAT_TYPE */
|
|
1236
|
173
|
1237 sprintf (buffer, "%ld", (long) (XINT (num)));
|
0
|
1238 return build_string (buffer);
|
|
1239 }
|
|
1240
|
169
|
1241 static int
|
|
1242 digit_to_number (int character, int base)
|
|
1243 {
|
|
1244 int digit;
|
|
1245
|
|
1246 if (character >= '0' && character <= '9')
|
|
1247 digit = character - '0';
|
|
1248 else if (character >= 'a' && character <= 'z')
|
|
1249 digit = character - 'a' + 10;
|
|
1250 else if (character >= 'A' && character <= 'Z')
|
|
1251 digit = character - 'A' + 10;
|
|
1252 else
|
|
1253 return -1;
|
|
1254
|
|
1255 if (digit >= base)
|
|
1256 return -1;
|
|
1257 else
|
|
1258 return digit;
|
|
1259 }
|
|
1260
|
|
1261 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
|
0
|
1262 Convert STRING to a number by parsing it as a decimal number.
|
|
1263 This parses both integers and floating point numbers.
|
|
1264 It ignores leading spaces and tabs.
|
169
|
1265
|
|
1266 If BASE, interpret STRING as a number in that base. If BASE isn't
|
|
1267 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
|
|
1268 Floating point numbers always use base 10.
|
20
|
1269 */
|
169
|
1270 (string, base))
|
0
|
1271 {
|
|
1272 char *p;
|
169
|
1273 int b;
|
|
1274
|
0
|
1275 CHECK_STRING (string);
|
|
1276
|
169
|
1277 if (NILP (base))
|
|
1278 b = 10;
|
|
1279 else
|
|
1280 {
|
|
1281 CHECK_INT (base);
|
|
1282 b = XINT (base);
|
171
|
1283 check_int_range (b, 2, 16);
|
169
|
1284 }
|
|
1285
|
16
|
1286 p = (char *) XSTRING_DATA (string);
|
169
|
1287
|
0
|
1288 /* Skip any whitespace at the front of the number. Some versions of
|
|
1289 atoi do this anyway, so we might as well make Emacs lisp consistent. */
|
|
1290 while (*p == ' ' || *p == '\t')
|
|
1291 p++;
|
|
1292
|
|
1293 #ifdef LISP_FLOAT_TYPE
|
|
1294 if (isfloat_string (p))
|
|
1295 return make_float (atof (p));
|
|
1296 #endif /* LISP_FLOAT_TYPE */
|
|
1297
|
171
|
1298 if (b == 10)
|
169
|
1299 {
|
|
1300 /* Use the system-provided functions for base 10. */
|
|
1301 Lisp_Object value;
|
|
1302 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1303 XSETINT (value, atoi (p));
|
|
1304 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1305 XSETINT (value, atol (p));
|
|
1306 else
|
|
1307 abort ();
|
|
1308 return value;
|
|
1309 }
|
0
|
1310 else
|
169
|
1311 {
|
|
1312 int digit, negative = 1;
|
|
1313 EMACS_INT v = 0;
|
|
1314
|
|
1315 if (*p == '-')
|
|
1316 {
|
|
1317 negative = -1;
|
|
1318 p++;
|
|
1319 }
|
|
1320 else if (*p == '+')
|
173
|
1321 p++;
|
169
|
1322 while (1)
|
|
1323 {
|
|
1324 digit = digit_to_number (*p++, b);
|
|
1325 if (digit < 0)
|
|
1326 break;
|
|
1327 v = v * b + digit;
|
|
1328 }
|
|
1329 return make_int (negative * v);
|
|
1330 }
|
0
|
1331 }
|
173
|
1332
|
0
|
1333 enum arithop
|
|
1334 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
|
|
1335
|
70
|
1336
|
0
|
1337 #ifdef LISP_FLOAT_TYPE
|
|
1338 static Lisp_Object
|
|
1339 float_arith_driver (double accum, int argnum, enum arithop code, int nargs,
|
|
1340 Lisp_Object *args)
|
|
1341 {
|
|
1342 REGISTER Lisp_Object val;
|
|
1343 double next;
|
173
|
1344
|
0
|
1345 for (; argnum < nargs; argnum++)
|
|
1346 {
|
16
|
1347 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
|
|
1348 val = args[argnum];
|
0
|
1349 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
|
|
1350
|
|
1351 if (FLOATP (val))
|
|
1352 {
|
|
1353 next = float_data (XFLOAT (val));
|
|
1354 }
|
|
1355 else
|
|
1356 {
|
|
1357 args[argnum] = val; /* runs into a compiler bug. */
|
|
1358 next = XINT (args[argnum]);
|
|
1359 }
|
|
1360 switch (code)
|
|
1361 {
|
|
1362 case Aadd:
|
|
1363 accum += next;
|
|
1364 break;
|
|
1365 case Asub:
|
|
1366 if (!argnum && nargs != 1)
|
|
1367 next = - next;
|
|
1368 accum -= next;
|
|
1369 break;
|
|
1370 case Amult:
|
|
1371 accum *= next;
|
|
1372 break;
|
|
1373 case Adiv:
|
|
1374 if (!argnum)
|
|
1375 accum = next;
|
|
1376 else
|
|
1377 {
|
|
1378 if (next == 0)
|
|
1379 Fsignal (Qarith_error, Qnil);
|
|
1380 accum /= next;
|
|
1381 }
|
|
1382 break;
|
|
1383 case Alogand:
|
|
1384 case Alogior:
|
|
1385 case Alogxor:
|
70
|
1386 return wrong_type_argument (Qinteger_char_or_marker_p, val);
|
0
|
1387 case Amax:
|
|
1388 if (!argnum || isnan (next) || next > accum)
|
|
1389 accum = next;
|
|
1390 break;
|
|
1391 case Amin:
|
|
1392 if (!argnum || isnan (next) || next < accum)
|
|
1393 accum = next;
|
|
1394 break;
|
|
1395 }
|
|
1396 }
|
|
1397
|
|
1398 return make_float (accum);
|
|
1399 }
|
|
1400 #endif /* LISP_FLOAT_TYPE */
|
|
1401
|
16
|
1402 static Lisp_Object
|
|
1403 arith_driver (enum arithop code, int nargs, Lisp_Object *args)
|
|
1404 {
|
|
1405 Lisp_Object val;
|
|
1406 REGISTER int argnum;
|
|
1407 REGISTER EMACS_INT accum = 0;
|
|
1408 REGISTER EMACS_INT next;
|
|
1409
|
|
1410 switch (code)
|
|
1411 {
|
|
1412 case Alogior:
|
|
1413 case Alogxor:
|
|
1414 case Aadd:
|
|
1415 case Asub:
|
|
1416 accum = 0; break;
|
|
1417 case Amult:
|
|
1418 accum = 1; break;
|
|
1419 case Alogand:
|
|
1420 accum = -1; break;
|
|
1421 case Adiv:
|
|
1422 case Amax:
|
|
1423 case Amin:
|
|
1424 accum = 0; break;
|
|
1425 default:
|
|
1426 abort ();
|
|
1427 }
|
|
1428
|
|
1429 for (argnum = 0; argnum < nargs; argnum++)
|
|
1430 {
|
|
1431 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
|
|
1432 val = args[argnum];
|
|
1433 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
|
|
1434
|
|
1435 #ifdef LISP_FLOAT_TYPE
|
|
1436 if (FLOATP (val)) /* time to do serious math */
|
173
|
1437 return float_arith_driver ((double) accum, argnum, code,
|
|
1438 nargs, args);
|
16
|
1439 #endif /* LISP_FLOAT_TYPE */
|
|
1440 args[argnum] = val; /* runs into a compiler bug. */
|
|
1441 next = XINT (args[argnum]);
|
|
1442 switch (code)
|
|
1443 {
|
|
1444 case Aadd: accum += next; break;
|
|
1445 case Asub:
|
|
1446 if (!argnum && nargs != 1)
|
|
1447 next = - next;
|
|
1448 accum -= next;
|
|
1449 break;
|
|
1450 case Amult: accum *= next; break;
|
|
1451 case Adiv:
|
|
1452 if (!argnum) accum = next;
|
|
1453 else
|
|
1454 {
|
|
1455 if (next == 0)
|
|
1456 Fsignal (Qarith_error, Qnil);
|
|
1457 accum /= next;
|
|
1458 }
|
|
1459 break;
|
|
1460 case Alogand: accum &= next; break;
|
|
1461 case Alogior: accum |= next; break;
|
|
1462 case Alogxor: accum ^= next; break;
|
|
1463 case Amax: if (!argnum || next > accum) accum = next; break;
|
|
1464 case Amin: if (!argnum || next < accum) accum = next; break;
|
|
1465 }
|
|
1466 }
|
|
1467
|
|
1468 XSETINT (val, accum);
|
|
1469 return val;
|
|
1470 }
|
|
1471
|
20
|
1472 DEFUN ("+", Fplus, 0, MANY, 0, /*
|
16
|
1473 Return sum of any number of arguments.
|
70
|
1474 The arguments should all be numbers, characters or markers.
|
20
|
1475 */
|
|
1476 (int nargs, Lisp_Object *args))
|
0
|
1477 {
|
|
1478 return arith_driver (Aadd, nargs, args);
|
|
1479 }
|
|
1480
|
20
|
1481 DEFUN ("-", Fminus, 0, MANY, 0, /*
|
70
|
1482 Negate number or subtract numbers, characters or markers.
|
0
|
1483 With one arg, negates it. With more than one arg,
|
|
1484 subtracts all but the first from the first.
|
20
|
1485 */
|
|
1486 (int nargs, Lisp_Object *args))
|
0
|
1487 {
|
|
1488 return arith_driver (Asub, nargs, args);
|
|
1489 }
|
|
1490
|
20
|
1491 DEFUN ("*", Ftimes, 0, MANY, 0, /*
|
16
|
1492 Return product of any number of arguments.
|
70
|
1493 The arguments should all be numbers, characters or markers.
|
20
|
1494 */
|
|
1495 (int nargs, Lisp_Object *args))
|
0
|
1496 {
|
|
1497 return arith_driver (Amult, nargs, args);
|
|
1498 }
|
|
1499
|
20
|
1500 DEFUN ("/", Fquo, 2, MANY, 0, /*
|
0
|
1501 Return first argument divided by all the remaining arguments.
|
70
|
1502 The arguments must be numbers, characters or markers.
|
20
|
1503 */
|
|
1504 (int nargs, Lisp_Object *args))
|
0
|
1505 {
|
|
1506 return arith_driver (Adiv, nargs, args);
|
|
1507 }
|
|
1508
|
20
|
1509 DEFUN ("%", Frem, 2, 2, 0, /*
|
0
|
1510 Return remainder of first arg divided by second.
|
70
|
1511 Both must be integers, characters or markers.
|
20
|
1512 */
|
|
1513 (num1, num2))
|
0
|
1514 {
|
|
1515 CHECK_INT_COERCE_CHAR_OR_MARKER (num1);
|
|
1516 CHECK_INT_COERCE_CHAR_OR_MARKER (num2);
|
|
1517
|
|
1518 if (ZEROP (num2))
|
|
1519 Fsignal (Qarith_error, Qnil);
|
|
1520
|
173
|
1521 return make_int (XINT (num1) % XINT (num2));
|
0
|
1522 }
|
|
1523
|
|
1524 /* Note, ANSI *requires* the presence of the fmod() library routine.
|
|
1525 If your system doesn't have it, complain to your vendor, because
|
|
1526 that is a bug. */
|
|
1527
|
|
1528 #ifndef HAVE_FMOD
|
|
1529 double
|
|
1530 fmod (double f1, double f2)
|
|
1531 {
|
|
1532 if (f2 < 0.0)
|
|
1533 f2 = -f2;
|
173
|
1534 return f1 - f2 * floor (f1/f2);
|
0
|
1535 }
|
|
1536 #endif /* ! HAVE_FMOD */
|
|
1537
|
|
1538
|
20
|
1539 DEFUN ("mod", Fmod, 2, 2, 0, /*
|
0
|
1540 Return X modulo Y.
|
|
1541 The result falls between zero (inclusive) and Y (exclusive).
|
70
|
1542 Both X and Y must be numbers, characters or markers.
|
0
|
1543 If either argument is a float, a float will be returned.
|
20
|
1544 */
|
|
1545 (x, y))
|
0
|
1546 {
|
|
1547 EMACS_INT i1, i2;
|
|
1548
|
|
1549 #ifdef LISP_FLOAT_TYPE
|
|
1550 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (x);
|
|
1551 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (y);
|
|
1552
|
|
1553 if (FLOATP (x) || FLOATP (y))
|
|
1554 {
|
|
1555 double f1, f2;
|
|
1556
|
|
1557 f1 = ((FLOATP (x)) ? float_data (XFLOAT (x)) : XINT (x));
|
|
1558 f2 = ((FLOATP (y)) ? float_data (XFLOAT (y)) : XINT (y));
|
|
1559 if (f2 == 0)
|
|
1560 Fsignal (Qarith_error, Qnil);
|
|
1561
|
173
|
1562 f1 = fmod (f1, f2);
|
0
|
1563
|
|
1564 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
1565 if (f2 < 0 ? f1 > 0 : f1 < 0)
|
|
1566 f1 += f2;
|
173
|
1567 return make_float (f1);
|
0
|
1568 }
|
|
1569 #else /* not LISP_FLOAT_TYPE */
|
|
1570 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (x);
|
|
1571 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (y);
|
|
1572 #endif /* not LISP_FLOAT_TYPE */
|
|
1573
|
|
1574 i1 = XINT (x);
|
|
1575 i2 = XINT (y);
|
|
1576
|
|
1577 if (i2 == 0)
|
|
1578 Fsignal (Qarith_error, Qnil);
|
173
|
1579
|
0
|
1580 i1 %= i2;
|
|
1581
|
|
1582 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
1583 if (i2 < 0 ? i1 > 0 : i1 < 0)
|
|
1584 i1 += i2;
|
|
1585
|
173
|
1586 return make_int (i1);
|
0
|
1587 }
|
|
1588
|
|
1589
|
20
|
1590 DEFUN ("max", Fmax, 1, MANY, 0, /*
|
16
|
1591 Return largest of all the arguments.
|
70
|
1592 All arguments must be numbers, characters or markers.
|
|
1593 The value is always a number; markers and characters are converted
|
|
1594 to numbers.
|
20
|
1595 */
|
|
1596 (int nargs, Lisp_Object *args))
|
0
|
1597 {
|
|
1598 return arith_driver (Amax, nargs, args);
|
|
1599 }
|
|
1600
|
20
|
1601 DEFUN ("min", Fmin, 1, MANY, 0, /*
|
16
|
1602 Return smallest of all the arguments.
|
70
|
1603 All arguments must be numbers, characters or markers.
|
|
1604 The value is always a number; markers and characters are converted
|
|
1605 to numbers.
|
20
|
1606 */
|
|
1607 (int nargs, Lisp_Object *args))
|
0
|
1608 {
|
|
1609 return arith_driver (Amin, nargs, args);
|
|
1610 }
|
|
1611
|
20
|
1612 DEFUN ("logand", Flogand, 0, MANY, 0, /*
|
0
|
1613 Return bitwise-and of all the arguments.
|
70
|
1614 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1615 */
|
|
1616 (int nargs, Lisp_Object *args))
|
0
|
1617 {
|
|
1618 return arith_driver (Alogand, nargs, args);
|
|
1619 }
|
|
1620
|
20
|
1621 DEFUN ("logior", Flogior, 0, MANY, 0, /*
|
0
|
1622 Return bitwise-or of all the arguments.
|
70
|
1623 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1624 */
|
|
1625 (int nargs, Lisp_Object *args))
|
0
|
1626 {
|
|
1627 return arith_driver (Alogior, nargs, args);
|
|
1628 }
|
|
1629
|
20
|
1630 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
|
0
|
1631 Return bitwise-exclusive-or of all the arguments.
|
70
|
1632 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1633 */
|
|
1634 (int nargs, Lisp_Object *args))
|
0
|
1635 {
|
|
1636 return arith_driver (Alogxor, nargs, args);
|
|
1637 }
|
|
1638
|
20
|
1639 DEFUN ("ash", Fash, 2, 2, 0, /*
|
0
|
1640 Return VALUE with its bits shifted left by COUNT.
|
|
1641 If COUNT is negative, shifting is actually to the right.
|
|
1642 In this case, the sign bit is duplicated.
|
20
|
1643 */
|
|
1644 (value, count))
|
0
|
1645 {
|
|
1646 CHECK_INT_COERCE_CHAR (value);
|
|
1647 CHECK_INT (count);
|
|
1648
|
16
|
1649 return make_int (XINT (count) > 0 ?
|
70
|
1650 XINT (value) << XINT (count) :
|
|
1651 XINT (value) >> -XINT (count));
|
0
|
1652 }
|
|
1653
|
20
|
1654 DEFUN ("lsh", Flsh, 2, 2, 0, /*
|
0
|
1655 Return VALUE with its bits shifted left by COUNT.
|
|
1656 If COUNT is negative, shifting is actually to the right.
|
70
|
1657 In this case, zeros are shifted in on the left.
|
20
|
1658 */
|
|
1659 (value, count))
|
0
|
1660 {
|
|
1661 Lisp_Object val;
|
|
1662
|
|
1663 CHECK_INT_COERCE_CHAR (value);
|
|
1664 CHECK_INT (count);
|
|
1665
|
70
|
1666 {
|
|
1667 int C_count = XINT (count);
|
207
|
1668 /* EMACS_UINT C_value = (EMACS_UINT) XUINT (value);*/
|
|
1669 EMACS_UINT C_value = (EMACS_UINT) XINT (value);
|
70
|
1670 XSETINT (val, C_count > 0 ? C_value << C_count : C_value >> -C_count);
|
|
1671 }
|
0
|
1672 return val;
|
|
1673 }
|
|
1674
|
20
|
1675 DEFUN ("1+", Fadd1, 1, 1, 0, /*
|
0
|
1676 Return NUMBER plus one. NUMBER may be a number or a marker.
|
70
|
1677 Markers and characters are converted to integers.
|
20
|
1678 */
|
|
1679 (number))
|
0
|
1680 {
|
|
1681 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (number);
|
|
1682
|
|
1683 #ifdef LISP_FLOAT_TYPE
|
|
1684 if (FLOATP (number))
|
173
|
1685 return make_float (1.0 + float_data (XFLOAT (number)));
|
0
|
1686 #endif /* LISP_FLOAT_TYPE */
|
|
1687
|
173
|
1688 return make_int (XINT (number) + 1);
|
0
|
1689 }
|
|
1690
|
20
|
1691 DEFUN ("1-", Fsub1, 1, 1, 0, /*
|
0
|
1692 Return NUMBER minus one. NUMBER may be a number or a marker.
|
70
|
1693 Markers and characters are converted to integers.
|
20
|
1694 */
|
|
1695 (number))
|
0
|
1696 {
|
|
1697 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (number);
|
|
1698
|
|
1699 #ifdef LISP_FLOAT_TYPE
|
|
1700 if (FLOATP (number))
|
173
|
1701 return make_float (-1.0 + (float_data (XFLOAT (number))));
|
0
|
1702 #endif /* LISP_FLOAT_TYPE */
|
|
1703
|
173
|
1704 return make_int (XINT (number) - 1);
|
0
|
1705 }
|
|
1706
|
20
|
1707 DEFUN ("lognot", Flognot, 1, 1, 0, /*
|
0
|
1708 Return the bitwise complement of NUMBER. NUMBER must be an integer.
|
20
|
1709 */
|
|
1710 (number))
|
0
|
1711 {
|
|
1712 CHECK_INT (number);
|
173
|
1713 return make_int (~XINT (number));
|
0
|
1714 }
|
|
1715
|
|
1716
|
|
1717 /************************************************************************/
|
|
1718 /* weak lists */
|
|
1719 /************************************************************************/
|
|
1720
|
|
1721 /* A weak list is like a normal list except that elements automatically
|
|
1722 disappear when no longer in use, i.e. when no longer GC-protected.
|
|
1723 The basic idea is that we don't mark the elements during GC, but
|
|
1724 wait for them to be marked elsewhere. If they're not marked, we
|
|
1725 remove them. This is analogous to weak hashtables; see the explanation
|
|
1726 there for more info. */
|
|
1727
|
|
1728 static Lisp_Object mark_weak_list (Lisp_Object, void (*) (Lisp_Object));
|
|
1729 static void print_weak_list (Lisp_Object, Lisp_Object, int);
|
|
1730 static int weak_list_equal (Lisp_Object, Lisp_Object, int depth);
|
|
1731 static unsigned long weak_list_hash (Lisp_Object obj, int depth);
|
|
1732 DEFINE_LRECORD_IMPLEMENTATION ("weak-list", weak_list,
|
|
1733 mark_weak_list, print_weak_list,
|
|
1734 0, weak_list_equal, weak_list_hash,
|
|
1735 struct weak_list);
|
|
1736
|
|
1737 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
|
|
1738
|
|
1739 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
|
|
1740
|
|
1741 static Lisp_Object
|
|
1742 mark_weak_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
1743 {
|
|
1744 return Qnil; /* nichts ist gemarkt */
|
|
1745 }
|
|
1746
|
|
1747 static void
|
|
1748 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1749 {
|
|
1750 if (print_readably)
|
|
1751 error ("printing unreadable object #<weak-list>");
|
173
|
1752
|
0
|
1753 write_c_string ("#<weak-list ", printcharfun);
|
|
1754 print_internal (encode_weak_list_type (XWEAK_LIST (obj)->type),
|
|
1755 printcharfun, 0);
|
|
1756 write_c_string (" ", printcharfun);
|
|
1757 print_internal (XWEAK_LIST (obj)->list, printcharfun, escapeflag);
|
|
1758 write_c_string (">", printcharfun);
|
|
1759 }
|
|
1760
|
|
1761 static int
|
|
1762 weak_list_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
1763 {
|
|
1764 struct weak_list *w1 = XWEAK_LIST (o1);
|
|
1765 struct weak_list *w2 = XWEAK_LIST (o2);
|
|
1766
|
173
|
1767 return ((w1->type == w2->type) &&
|
|
1768 internal_equal (w1->list, w2->list, depth + 1));
|
0
|
1769 }
|
|
1770
|
|
1771 static unsigned long
|
|
1772 weak_list_hash (Lisp_Object obj, int depth)
|
|
1773 {
|
|
1774 struct weak_list *w = XWEAK_LIST (obj);
|
|
1775
|
|
1776 return HASH2 ((unsigned long) w->type,
|
|
1777 internal_hash (w->list, depth + 1));
|
|
1778 }
|
|
1779
|
|
1780 Lisp_Object
|
|
1781 make_weak_list (enum weak_list_type type)
|
|
1782 {
|
|
1783 Lisp_Object result = Qnil;
|
185
|
1784 struct weak_list *wl =
|
|
1785 alloc_lcrecord_type (struct weak_list, lrecord_weak_list);
|
0
|
1786
|
|
1787 wl->list = Qnil;
|
|
1788 wl->type = type;
|
|
1789 XSETWEAK_LIST (result, wl);
|
|
1790 wl->next_weak = Vall_weak_lists;
|
|
1791 Vall_weak_lists = result;
|
|
1792 return result;
|
|
1793 }
|
|
1794
|
|
1795 /*
|
|
1796 -- we do not mark the list elements (either the elements themselves
|
|
1797 or the cons cells that hold them) in the normal marking phase.
|
|
1798 -- at the end of marking, we go through all weak lists that are
|
|
1799 marked, and mark the cons cells that hold all marked
|
|
1800 objects, and possibly parts of the objects themselves.
|
|
1801 (See alloc.c, "after-mark".)
|
|
1802 -- after that, we prune away all the cons cells that are not marked.
|
|
1803
|
|
1804 WARNING WARNING WARNING WARNING WARNING:
|
|
1805
|
|
1806 The code in the following two functions is *unbelievably* tricky.
|
|
1807 Don't mess with it. You'll be sorry.
|
|
1808
|
|
1809 Linked lists just majorly suck, d'ya know?
|
|
1810 */
|
|
1811
|
|
1812 int
|
|
1813 finish_marking_weak_lists (int (*obj_marked_p) (Lisp_Object),
|
|
1814 void (*markobj) (Lisp_Object))
|
|
1815 {
|
|
1816 Lisp_Object rest;
|
|
1817 int did_mark = 0;
|
|
1818
|
|
1819 for (rest = Vall_weak_lists;
|
|
1820 !GC_NILP (rest);
|
|
1821 rest = XWEAK_LIST (rest)->next_weak)
|
|
1822 {
|
|
1823 Lisp_Object rest2;
|
|
1824 enum weak_list_type type = XWEAK_LIST (rest)->type;
|
|
1825
|
|
1826 if (! ((*obj_marked_p) (rest)))
|
|
1827 /* The weak list is probably garbage. Ignore it. */
|
|
1828 continue;
|
|
1829
|
|
1830 for (rest2 = XWEAK_LIST (rest)->list;
|
|
1831 /* We need to be trickier since we're inside of GC;
|
|
1832 use CONSP instead of !NILP in case of user-visible
|
|
1833 imperfect lists */
|
|
1834 GC_CONSP (rest2);
|
|
1835 rest2 = XCDR (rest2))
|
|
1836 {
|
|
1837 Lisp_Object elem;
|
|
1838 /* If the element is "marked" (meaning depends on the type
|
|
1839 of weak list), we need to mark the cons containing the
|
|
1840 element, and maybe the element itself (if only some part
|
|
1841 was already marked). */
|
|
1842 int need_to_mark_cons = 0;
|
|
1843 int need_to_mark_elem = 0;
|
|
1844
|
|
1845 /* If a cons is already marked, then its car is already marked
|
|
1846 (either because of an external pointer or because of
|
|
1847 a previous call to this function), and likewise for all
|
|
1848 the rest of the elements in the list, so we can stop now. */
|
|
1849 if ((*obj_marked_p) (rest2))
|
|
1850 break;
|
|
1851
|
|
1852 elem = XCAR (rest2);
|
|
1853
|
|
1854 switch (type)
|
|
1855 {
|
|
1856 case WEAK_LIST_SIMPLE:
|
|
1857 if ((*obj_marked_p) (elem))
|
|
1858 need_to_mark_cons = 1;
|
|
1859 break;
|
|
1860
|
|
1861 case WEAK_LIST_ASSOC:
|
|
1862 if (!GC_CONSP (elem))
|
|
1863 {
|
|
1864 /* just leave bogus elements there */
|
|
1865 need_to_mark_cons = 1;
|
|
1866 need_to_mark_elem = 1;
|
|
1867 }
|
|
1868 else if ((*obj_marked_p) (XCAR (elem)) &&
|
|
1869 (*obj_marked_p) (XCDR (elem)))
|
|
1870 {
|
|
1871 need_to_mark_cons = 1;
|
|
1872 /* We still need to mark elem, because it's
|
|
1873 probably not marked. */
|
|
1874 need_to_mark_elem = 1;
|
|
1875 }
|
|
1876 break;
|
|
1877
|
|
1878 case WEAK_LIST_KEY_ASSOC:
|
|
1879 if (!GC_CONSP (elem))
|
|
1880 {
|
|
1881 /* just leave bogus elements there */
|
|
1882 need_to_mark_cons = 1;
|
|
1883 need_to_mark_elem = 1;
|
|
1884 }
|
|
1885 else if ((*obj_marked_p) (XCAR (elem)))
|
|
1886 {
|
|
1887 need_to_mark_cons = 1;
|
|
1888 /* We still need to mark elem and XCDR (elem);
|
|
1889 marking elem does both */
|
|
1890 need_to_mark_elem = 1;
|
|
1891 }
|
|
1892 break;
|
|
1893
|
|
1894 case WEAK_LIST_VALUE_ASSOC:
|
|
1895 if (!GC_CONSP (elem))
|
|
1896 {
|
|
1897 /* just leave bogus elements there */
|
|
1898 need_to_mark_cons = 1;
|
|
1899 need_to_mark_elem = 1;
|
|
1900 }
|
|
1901 else if ((*obj_marked_p) (XCDR (elem)))
|
|
1902 {
|
|
1903 need_to_mark_cons = 1;
|
|
1904 /* We still need to mark elem and XCAR (elem);
|
|
1905 marking elem does both */
|
|
1906 need_to_mark_elem = 1;
|
|
1907 }
|
|
1908 break;
|
|
1909
|
|
1910 default:
|
|
1911 abort ();
|
|
1912 }
|
|
1913
|
|
1914 if (need_to_mark_elem && ! (*obj_marked_p) (elem))
|
|
1915 {
|
|
1916 (*markobj) (elem);
|
|
1917 did_mark = 1;
|
|
1918 }
|
|
1919
|
|
1920 /* We also need to mark the cons that holds the elem or
|
|
1921 assoc-pair. We do *not* want to call (markobj) here
|
|
1922 because that will mark the entire list; we just want to
|
|
1923 mark the cons itself.
|
|
1924 */
|
|
1925 if (need_to_mark_cons)
|
|
1926 {
|
|
1927 struct Lisp_Cons *ptr = XCONS (rest2);
|
|
1928 if (!CONS_MARKED_P (ptr))
|
|
1929 {
|
|
1930 MARK_CONS (ptr);
|
|
1931 did_mark = 1;
|
|
1932 }
|
|
1933 }
|
|
1934 }
|
|
1935
|
|
1936 /* In case of imperfect list, need to mark the final cons
|
|
1937 because we're not removing it */
|
|
1938 if (!GC_NILP (rest2) && ! (obj_marked_p) (rest2))
|
|
1939 {
|
|
1940 (markobj) (rest2);
|
|
1941 did_mark = 1;
|
|
1942 }
|
|
1943 }
|
|
1944
|
|
1945 return did_mark;
|
|
1946 }
|
|
1947
|
|
1948 void
|
|
1949 prune_weak_lists (int (*obj_marked_p) (Lisp_Object))
|
|
1950 {
|
|
1951 Lisp_Object rest, prev = Qnil;
|
|
1952
|
|
1953 for (rest = Vall_weak_lists;
|
|
1954 !GC_NILP (rest);
|
|
1955 rest = XWEAK_LIST (rest)->next_weak)
|
|
1956 {
|
|
1957 if (! ((*obj_marked_p) (rest)))
|
|
1958 {
|
|
1959 /* This weak list itself is garbage. Remove it from the list. */
|
|
1960 if (GC_NILP (prev))
|
|
1961 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
|
|
1962 else
|
|
1963 XWEAK_LIST (prev)->next_weak =
|
|
1964 XWEAK_LIST (rest)->next_weak;
|
|
1965 }
|
|
1966 else
|
|
1967 {
|
|
1968 Lisp_Object rest2, prev2 = Qnil;
|
|
1969 Lisp_Object tortoise;
|
|
1970 int go_tortoise = 0;
|
|
1971
|
|
1972 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
|
|
1973 /* We need to be trickier since we're inside of GC;
|
|
1974 use CONSP instead of !NILP in case of user-visible
|
|
1975 imperfect lists */
|
|
1976 GC_CONSP (rest2);)
|
|
1977 {
|
|
1978 /* It suffices to check the cons for marking,
|
|
1979 regardless of the type of weak list:
|
|
1980
|
|
1981 -- if the cons is pointed to somewhere else,
|
|
1982 then it should stay around and will be marked.
|
|
1983 -- otherwise, if it should stay around, it will
|
|
1984 have been marked in finish_marking_weak_lists().
|
|
1985 -- otherwise, it's not marked and should disappear.
|
|
1986 */
|
|
1987 if (!(*obj_marked_p) (rest2))
|
|
1988 {
|
|
1989 /* bye bye :-( */
|
|
1990 if (GC_NILP (prev2))
|
|
1991 XWEAK_LIST (rest)->list = XCDR (rest2);
|
|
1992 else
|
|
1993 XCDR (prev2) = XCDR (rest2);
|
|
1994 rest2 = XCDR (rest2);
|
|
1995 /* Ouch. Circularity checking is even trickier
|
|
1996 than I thought. When we cut out a link
|
|
1997 like this, we can't advance the turtle or
|
|
1998 it'll catch up to us. Imagine that we're
|
|
1999 standing on floor tiles and moving forward --
|
|
2000 what we just did here is as if the floor
|
|
2001 tile under us just disappeared and all the
|
|
2002 ones ahead of us slid one tile towards us.
|
|
2003 In other words, we didn't move at all;
|
|
2004 if the tortoise was one step behind us
|
|
2005 previously, it still is, and therefore
|
|
2006 it must not move. */
|
|
2007 }
|
|
2008 else
|
|
2009 {
|
|
2010 prev2 = rest2;
|
|
2011
|
|
2012 /* Implementing circularity checking is trickier here
|
|
2013 than in other places because we have to guarantee
|
|
2014 that we've processed all elements before exiting
|
|
2015 due to a circularity. (In most places, an error
|
|
2016 is issued upon encountering a circularity, so it
|
|
2017 doesn't really matter if all elements are processed.)
|
|
2018 The idea is that we process along with the hare
|
|
2019 rather than the tortoise. If at any point in
|
|
2020 our forward process we encounter the tortoise,
|
|
2021 we must have already visited the spot, so we exit.
|
|
2022 (If we process with the tortoise, we can fail to
|
|
2023 process cases where a cons points to itself, or
|
|
2024 where cons A points to cons B, which points to
|
|
2025 cons A.) */
|
173
|
2026
|
0
|
2027 rest2 = XCDR (rest2);
|
|
2028 if (go_tortoise)
|
|
2029 tortoise = XCDR (tortoise);
|
|
2030 go_tortoise = !go_tortoise;
|
|
2031 if (GC_EQ (rest2, tortoise))
|
|
2032 break;
|
|
2033 }
|
|
2034 }
|
|
2035
|
|
2036 prev = rest;
|
|
2037 }
|
|
2038 }
|
|
2039 }
|
|
2040
|
|
2041 static enum weak_list_type
|
|
2042 decode_weak_list_type (Lisp_Object symbol)
|
|
2043 {
|
|
2044 CHECK_SYMBOL (symbol);
|
16
|
2045 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
|
|
2046 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
|
70
|
2047 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
|
16
|
2048 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
|
|
2049 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
|
0
|
2050
|
|
2051 signal_simple_error ("Invalid weak list type", symbol);
|
|
2052 return WEAK_LIST_SIMPLE; /* not reached */
|
|
2053 }
|
|
2054
|
|
2055 static Lisp_Object
|
|
2056 encode_weak_list_type (enum weak_list_type type)
|
|
2057 {
|
|
2058 switch (type)
|
|
2059 {
|
16
|
2060 case WEAK_LIST_SIMPLE: return Qsimple;
|
|
2061 case WEAK_LIST_ASSOC: return Qassoc;
|
|
2062 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
|
|
2063 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
|
0
|
2064 default:
|
|
2065 abort ();
|
|
2066 }
|
|
2067
|
16
|
2068 return Qnil; /* not reached */
|
0
|
2069 }
|
|
2070
|
20
|
2071 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
|
0
|
2072 Return non-nil if OBJECT is a weak list.
|
20
|
2073 */
|
|
2074 (object))
|
0
|
2075 {
|
|
2076 return WEAK_LISTP (object) ? Qt : Qnil;
|
|
2077 }
|
|
2078
|
20
|
2079 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
|
0
|
2080 Create a new weak list.
|
|
2081 A weak list object is an object that contains a list. This list behaves
|
|
2082 like any other list except that its elements do not count towards
|
|
2083 garbage collection -- if the only pointer to an object in inside a weak
|
|
2084 list (other than pointers in similar objects such as weak hash tables),
|
|
2085 the object is garbage collected and automatically removed from the list.
|
|
2086 This is used internally, for example, to manage the list holding the
|
|
2087 children of an extent -- an extent that is unused but has a parent will
|
|
2088 still be reclaimed, and will automatically be removed from its parent's
|
|
2089 list of children.
|
|
2090
|
|
2091 Optional argument TYPE specifies the type of the weak list, and defaults
|
|
2092 to `simple'. Recognized types are
|
|
2093
|
|
2094 `simple' Objects in the list disappear if not pointed to.
|
|
2095 `assoc' Objects in the list disappear if they are conses
|
|
2096 and either the car or the cdr of the cons is not
|
|
2097 pointed to.
|
|
2098 `key-assoc' Objects in the list disappear if they are conses
|
|
2099 and the car is not pointed to.
|
|
2100 `value-assoc' Objects in the list disappear if they are conses
|
|
2101 and the cdr is not pointed to.
|
20
|
2102 */
|
|
2103 (type))
|
0
|
2104 {
|
|
2105 if (NILP (type))
|
|
2106 type = Qsimple;
|
|
2107
|
|
2108 return make_weak_list (decode_weak_list_type (type));
|
|
2109 }
|
|
2110
|
20
|
2111 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
|
0
|
2112 Return the type of the given weak-list object.
|
20
|
2113 */
|
|
2114 (weak))
|
0
|
2115 {
|
|
2116 CHECK_WEAK_LIST (weak);
|
|
2117 return encode_weak_list_type (XWEAK_LIST (weak)->type);
|
|
2118 }
|
|
2119
|
20
|
2120 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
|
0
|
2121 Return the list contained in a weak-list object.
|
20
|
2122 */
|
|
2123 (weak))
|
0
|
2124 {
|
|
2125 CHECK_WEAK_LIST (weak);
|
|
2126 return XWEAK_LIST_LIST (weak);
|
|
2127 }
|
|
2128
|
20
|
2129 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
|
0
|
2130 Change the list contained in a weak-list object.
|
20
|
2131 */
|
|
2132 (weak, new_list))
|
0
|
2133 {
|
|
2134 CHECK_WEAK_LIST (weak);
|
|
2135 XWEAK_LIST_LIST (weak) = new_list;
|
|
2136 return new_list;
|
|
2137 }
|
|
2138
|
|
2139
|
|
2140 /************************************************************************/
|
|
2141 /* initialization */
|
|
2142 /************************************************************************/
|
|
2143
|
|
2144 static SIGTYPE
|
|
2145 arith_error (int signo)
|
|
2146 {
|
|
2147 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
|
|
2148 EMACS_UNBLOCK_SIGNAL (signo);
|
|
2149 signal_error (Qarith_error, Qnil);
|
|
2150 }
|
|
2151
|
|
2152 void
|
|
2153 init_data_very_early (void)
|
|
2154 {
|
|
2155 /* Don't do this if just dumping out.
|
|
2156 We don't want to call `signal' in this case
|
|
2157 so that we don't have trouble with dumping
|
|
2158 signal-delivering routines in an inconsistent state. */
|
|
2159 #ifndef CANNOT_DUMP
|
|
2160 if (!initialized)
|
|
2161 return;
|
|
2162 #endif /* CANNOT_DUMP */
|
|
2163 signal (SIGFPE, arith_error);
|
|
2164 #ifdef uts
|
|
2165 signal (SIGEMT, arith_error);
|
|
2166 #endif /* uts */
|
|
2167 }
|
|
2168
|
|
2169 void
|
|
2170 init_errors_once_early (void)
|
|
2171 {
|
|
2172 defsymbol (&Qerror_conditions, "error-conditions");
|
|
2173 defsymbol (&Qerror_message, "error-message");
|
|
2174
|
|
2175 /* We declare the errors here because some other deferrors depend
|
|
2176 on some of the errors below. */
|
|
2177
|
|
2178 /* ERROR is used as a signaler for random errors for which nothing
|
|
2179 else is right */
|
|
2180
|
|
2181 deferror (&Qerror, "error", "error", Qnil);
|
|
2182 deferror (&Qquit, "quit", "Quit", Qnil);
|
|
2183
|
|
2184 deferror (&Qwrong_type_argument, "wrong-type-argument",
|
|
2185 "Wrong type argument", Qerror);
|
|
2186 deferror (&Qargs_out_of_range, "args-out-of-range", "Args out of range",
|
|
2187 Qerror);
|
|
2188 deferror (&Qvoid_function, "void-function",
|
|
2189 "Symbol's function definition is void", Qerror);
|
|
2190 deferror (&Qcyclic_function_indirection, "cyclic-function-indirection",
|
|
2191 "Symbol's chain of function indirections contains a loop", Qerror);
|
|
2192 deferror (&Qvoid_variable, "void-variable",
|
|
2193 "Symbol's value as variable is void", Qerror);
|
|
2194 deferror (&Qcyclic_variable_indirection, "cyclic-variable-indirection",
|
|
2195 "Symbol's chain of variable indirections contains a loop", Qerror);
|
|
2196 deferror (&Qsetting_constant, "setting-constant",
|
|
2197 "Attempt to set a constant symbol", Qerror);
|
|
2198 deferror (&Qinvalid_read_syntax, "invalid-read-syntax",
|
|
2199 "Invalid read syntax", Qerror);
|
|
2200 deferror (&Qmalformed_list, "malformed-list",
|
|
2201 "Malformed list", Qerror);
|
|
2202 deferror (&Qmalformed_property_list, "malformed-property-list",
|
|
2203 "Malformed property list", Qerror);
|
|
2204 deferror (&Qcircular_list, "circular-list",
|
|
2205 "Circular list", Qerror);
|
|
2206 deferror (&Qcircular_property_list, "circular-property-list",
|
|
2207 "Circular property list", Qerror);
|
|
2208 deferror (&Qinvalid_function, "invalid-function", "Invalid function",
|
|
2209 Qerror);
|
|
2210 deferror (&Qwrong_number_of_arguments, "wrong-number-of-arguments",
|
|
2211 "Wrong number of arguments", Qerror);
|
|
2212 deferror (&Qno_catch, "no-catch", "No catch for tag",
|
|
2213 Qerror);
|
|
2214 deferror (&Qbeginning_of_buffer, "beginning-of-buffer",
|
|
2215 "Beginning of buffer", Qerror);
|
|
2216 deferror (&Qend_of_buffer, "end-of-buffer", "End of buffer", Qerror);
|
|
2217 deferror (&Qbuffer_read_only, "buffer-read-only", "Buffer is read-only",
|
|
2218 Qerror);
|
|
2219
|
|
2220 deferror (&Qio_error, "io-error", "IO Error", Qerror);
|
|
2221 deferror (&Qend_of_file, "end-of-file", "End of stream", Qio_error);
|
|
2222
|
|
2223 deferror (&Qarith_error, "arith-error", "Arithmetic error", Qerror);
|
|
2224 deferror (&Qrange_error, "range-error", "Arithmetic range error",
|
|
2225 Qarith_error);
|
|
2226 deferror (&Qdomain_error, "domain-error", "Arithmetic domain error",
|
|
2227 Qarith_error);
|
|
2228 deferror (&Qsingularity_error, "singularity-error",
|
|
2229 "Arithmetic singularity error", Qdomain_error);
|
|
2230 deferror (&Qoverflow_error, "overflow-error",
|
|
2231 "Arithmetic overflow error", Qdomain_error);
|
|
2232 deferror (&Qunderflow_error, "underflow-error",
|
|
2233 "Arithmetic underflow error", Qdomain_error);
|
|
2234 }
|
|
2235
|
|
2236 void
|
|
2237 syms_of_data (void)
|
|
2238 {
|
|
2239 defsymbol (&Qcons, "cons");
|
|
2240 defsymbol (&Qkeyword, "keyword");
|
|
2241 /* Qstring, Qinteger, Qsymbol, Qvector defined in general.c */
|
|
2242
|
|
2243 defsymbol (&Qquote, "quote");
|
|
2244 defsymbol (&Qlambda, "lambda");
|
|
2245 defsymbol (&Qsignal, "signal");
|
|
2246 defsymbol (&Qtop_level, "top-level");
|
|
2247 defsymbol (&Qignore, "ignore");
|
|
2248
|
|
2249 defsymbol (&Qlistp, "listp");
|
|
2250 defsymbol (&Qconsp, "consp");
|
|
2251 defsymbol (&Qsubrp, "subrp");
|
|
2252 defsymbol (&Qsymbolp, "symbolp");
|
|
2253 defsymbol (&Qkeywordp, "keywordp");
|
|
2254 defsymbol (&Qintegerp, "integerp");
|
|
2255 defsymbol (&Qcharacterp, "characterp");
|
|
2256 defsymbol (&Qnatnump, "natnump");
|
|
2257 defsymbol (&Qstringp, "stringp");
|
|
2258 defsymbol (&Qarrayp, "arrayp");
|
|
2259 defsymbol (&Qsequencep, "sequencep");
|
|
2260 defsymbol (&Qbufferp, "bufferp");
|
|
2261 defsymbol (&Qbitp, "bitp");
|
|
2262 defsymbol (&Qbit_vectorp, "bit-vector-p");
|
|
2263 defsymbol (&Qvectorp, "vectorp");
|
|
2264 defsymbol (&Qcompiled_functionp, "compiled-function-p");
|
|
2265 defsymbol (&Qchar_or_string_p, "char-or-string-p");
|
|
2266 defsymbol (&Qmarkerp, "markerp");
|
|
2267 defsymbol (&Qinteger_or_marker_p, "integer-or-marker-p");
|
70
|
2268 defsymbol (&Qinteger_or_char_p, "integer-or-char-p");
|
|
2269 defsymbol (&Qinteger_char_or_marker_p, "integer-char-or-marker-p");
|
0
|
2270
|
|
2271 #ifdef LISP_FLOAT_TYPE
|
|
2272 defsymbol (&Qfloatp, "floatp");
|
|
2273 #endif /* LISP_FLOAT_TYPE */
|
|
2274 defsymbol (&Qnumberp, "numberp");
|
|
2275 defsymbol (&Qnumber_or_marker_p, "number-or-marker-p");
|
70
|
2276 defsymbol (&Qnumber_char_or_marker_p, "number-char-or-marker-p");
|
0
|
2277
|
|
2278 defsymbol (&Qcdr, "cdr");
|
|
2279
|
|
2280 defsymbol (&Qweak_listp, "weak-list-p");
|
|
2281
|
20
|
2282 DEFSUBR (Fwrong_type_argument);
|
0
|
2283
|
20
|
2284 DEFSUBR (Feq);
|
70
|
2285 DEFSUBR (Fold_eq);
|
20
|
2286 DEFSUBR (Fnull);
|
|
2287 DEFSUBR (Flistp);
|
|
2288 DEFSUBR (Fnlistp);
|
|
2289 DEFSUBR (Fconsp);
|
|
2290 DEFSUBR (Fatom);
|
|
2291 DEFSUBR (Fchar_or_string_p);
|
|
2292 DEFSUBR (Fcharacterp);
|
70
|
2293 DEFSUBR (Fchar_int_p);
|
104
|
2294 DEFSUBR (Fchar_to_int);
|
|
2295 DEFSUBR (Fint_to_char);
|
70
|
2296 DEFSUBR (Fchar_or_char_int_p);
|
20
|
2297 DEFSUBR (Fintegerp);
|
|
2298 DEFSUBR (Finteger_or_marker_p);
|
70
|
2299 DEFSUBR (Finteger_or_char_p);
|
|
2300 DEFSUBR (Finteger_char_or_marker_p);
|
20
|
2301 DEFSUBR (Fnumberp);
|
|
2302 DEFSUBR (Fnumber_or_marker_p);
|
70
|
2303 DEFSUBR (Fnumber_char_or_marker_p);
|
0
|
2304 #ifdef LISP_FLOAT_TYPE
|
20
|
2305 DEFSUBR (Ffloatp);
|
0
|
2306 #endif /* LISP_FLOAT_TYPE */
|
20
|
2307 DEFSUBR (Fnatnump);
|
|
2308 DEFSUBR (Fsymbolp);
|
|
2309 DEFSUBR (Fkeywordp);
|
|
2310 DEFSUBR (Fstringp);
|
|
2311 DEFSUBR (Fvectorp);
|
|
2312 DEFSUBR (Fbitp);
|
|
2313 DEFSUBR (Fbit_vector_p);
|
|
2314 DEFSUBR (Farrayp);
|
|
2315 DEFSUBR (Fsequencep);
|
|
2316 DEFSUBR (Fmarkerp);
|
|
2317 DEFSUBR (Fsubrp);
|
|
2318 DEFSUBR (Fsubr_min_args);
|
|
2319 DEFSUBR (Fsubr_max_args);
|
209
|
2320 DEFSUBR (Fsubr_interactive);
|
20
|
2321 DEFSUBR (Fcompiled_function_p);
|
|
2322 DEFSUBR (Ftype_of);
|
|
2323 DEFSUBR (Fcar);
|
|
2324 DEFSUBR (Fcdr);
|
|
2325 DEFSUBR (Fcar_safe);
|
|
2326 DEFSUBR (Fcdr_safe);
|
|
2327 DEFSUBR (Fsetcar);
|
|
2328 DEFSUBR (Fsetcdr);
|
|
2329 DEFSUBR (Findirect_function);
|
|
2330 DEFSUBR (Faref);
|
|
2331 DEFSUBR (Faset);
|
0
|
2332
|
20
|
2333 DEFSUBR (Fcompiled_function_instructions);
|
|
2334 DEFSUBR (Fcompiled_function_constants);
|
|
2335 DEFSUBR (Fcompiled_function_stack_depth);
|
|
2336 DEFSUBR (Fcompiled_function_arglist);
|
|
2337 DEFSUBR (Fcompiled_function_interactive);
|
|
2338 DEFSUBR (Fcompiled_function_doc_string);
|
|
2339 DEFSUBR (Fcompiled_function_domain);
|
0
|
2340 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
20
|
2341 DEFSUBR (Fcompiled_function_annotation);
|
0
|
2342 #endif
|
|
2343
|
20
|
2344 DEFSUBR (Fnumber_to_string);
|
|
2345 DEFSUBR (Fstring_to_number);
|
|
2346 DEFSUBR (Feqlsign);
|
|
2347 DEFSUBR (Flss);
|
|
2348 DEFSUBR (Fgtr);
|
|
2349 DEFSUBR (Fleq);
|
|
2350 DEFSUBR (Fgeq);
|
|
2351 DEFSUBR (Fneq);
|
|
2352 DEFSUBR (Fzerop);
|
|
2353 DEFSUBR (Fplus);
|
|
2354 DEFSUBR (Fminus);
|
|
2355 DEFSUBR (Ftimes);
|
|
2356 DEFSUBR (Fquo);
|
|
2357 DEFSUBR (Frem);
|
|
2358 DEFSUBR (Fmod);
|
|
2359 DEFSUBR (Fmax);
|
|
2360 DEFSUBR (Fmin);
|
|
2361 DEFSUBR (Flogand);
|
|
2362 DEFSUBR (Flogior);
|
|
2363 DEFSUBR (Flogxor);
|
|
2364 DEFSUBR (Flsh);
|
|
2365 DEFSUBR (Fash);
|
|
2366 DEFSUBR (Fadd1);
|
|
2367 DEFSUBR (Fsub1);
|
|
2368 DEFSUBR (Flognot);
|
0
|
2369
|
20
|
2370 DEFSUBR (Fweak_list_p);
|
|
2371 DEFSUBR (Fmake_weak_list);
|
|
2372 DEFSUBR (Fweak_list_type);
|
|
2373 DEFSUBR (Fweak_list_list);
|
|
2374 DEFSUBR (Fset_weak_list_list);
|
0
|
2375 }
|
|
2376
|
|
2377 void
|
|
2378 vars_of_data (void)
|
|
2379 {
|
|
2380 /* This must not be staticpro'd */
|
|
2381 Vall_weak_lists = Qnil;
|
70
|
2382
|
|
2383 #ifdef DEBUG_XEMACS
|
|
2384 DEFVAR_INT ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
|
|
2385 If non-nil, note when your code may be suffering from char-int confoundance.
|
|
2386 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
|
|
2387 etc. where a int and a char with the same value are being compared,
|
|
2388 it will issue a notice on stderr to this effect, along with a backtrace.
|
|
2389 In such situations, the result would be different in XEmacs 19 versus
|
|
2390 XEmacs 20, and you probably don't want this.
|
|
2391
|
|
2392 Note that in order to see these notices, you have to byte compile your
|
|
2393 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
|
|
2394 have its chars and ints all confounded in the byte code, making it
|
|
2395 impossible to accurately determine Ebola infection.
|
|
2396 */ );
|
|
2397
|
|
2398 debug_issue_ebola_notices = 2; /* #### temporary hack */
|
|
2399
|
|
2400 DEFVAR_INT ("debug-ebola-backtrace-length",
|
|
2401 &debug_ebola_backtrace_length /*
|
|
2402 Length (in stack frames) of short backtrace printed out in Ebola notices.
|
|
2403 See `debug-issue-ebola-notices'.
|
|
2404 */ );
|
159
|
2405 debug_ebola_backtrace_length = 32;
|
70
|
2406
|
|
2407 #endif /* DEBUG_XEMACS */
|
0
|
2408 }
|