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