comparison src/data.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 859a2309aef8
comparison
equal deleted inserted replaced
15:ad457d5f7d04 16:0293115a14e9
89 if (INTP (value) && EQ (predicate, Qstringp)) 89 if (INTP (value) && EQ (predicate, Qstringp))
90 return Fnumber_to_string (value); 90 return Fnumber_to_string (value);
91 if (CHARP (value) && EQ (predicate, Qstringp)) 91 if (CHARP (value) && EQ (predicate, Qstringp))
92 return Fchar_to_string (value); 92 return Fchar_to_string (value);
93 } 93 }
94 #endif 94 #endif /* MOCKLISP_SUPPORT */
95 value = Fsignal (Qwrong_type_argument, list2 (predicate, value)); 95 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
96 tem = call1 (predicate, value); 96 tem = call1 (predicate, value);
97 } 97 }
98 while (NILP (tem)); 98 while (NILP (tem));
99 return value; 99 return value;
176 /* characters do not need to sign extend so there's no need for special 176 /* characters do not need to sign extend so there's no need for special
177 futzing like with ints. */ 177 futzing like with ints. */
178 Lisp_Object 178 Lisp_Object
179 make_char (Emchar num) 179 make_char (Emchar num)
180 { 180 {
181 return make_int (num); 181 Lisp_Object val;
182 val = make_int (num);
183 return val;
182 } 184 }
183 185
184 /* Data type predicates */ 186 /* Data type predicates */
185 187
186 DEFUN ("eq", Feq, Seq, 2, 2, 0 /* 188 DEFUN ("eq", Feq, Seq, 2, 2, 0 /*
187 T if the two args are the same Lisp object. 189 T if the two args are the same Lisp object.
188 */ ) 190 */ )
189 (obj1, obj2) 191 (obj1, obj2)
190 Lisp_Object obj1, obj2; 192 Lisp_Object obj1, obj2;
191 { 193 {
192 if (EQ (obj1, obj2)) 194 return EQ (obj1, obj2) ? Qt : Qnil;
193 return Qt;
194 return Qnil;
195 } 195 }
196 196
197 DEFUN ("null", Fnull, Snull, 1, 1, 0 /* 197 DEFUN ("null", Fnull, Snull, 1, 1, 0 /*
198 T if OBJECT is nil. 198 T if OBJECT is nil.
199 */ ) 199 */ )
200 (object) 200 (object)
201 Lisp_Object object; 201 Lisp_Object object;
202 { 202 {
203 if (NILP (object)) 203 return NILP (object) ? Qt : Qnil;
204 return Qt;
205 return Qnil;
206 } 204 }
207 205
208 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0 /* 206 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0 /*
209 T if OBJECT is a cons cell. 207 T if OBJECT is a cons cell.
210 */ ) 208 */ )
211 (object) 209 (object)
212 Lisp_Object object; 210 Lisp_Object object;
213 { 211 {
214 if (CONSP (object)) 212 return CONSP (object) ? Qt : Qnil;
215 return Qt;
216 return Qnil;
217 } 213 }
218 214
219 DEFUN ("atom", Fatom, Satom, 1, 1, 0 /* 215 DEFUN ("atom", Fatom, Satom, 1, 1, 0 /*
220 T if OBJECT is not a cons cell. This includes nil. 216 T if OBJECT is not a cons cell. This includes nil.
221 */ ) 217 */ )
222 (object) 218 (object)
223 Lisp_Object object; 219 Lisp_Object object;
224 { 220 {
225 if (CONSP (object)) 221 return CONSP (object) ? Qnil : Qt;
226 return Qnil;
227 return Qt;
228 } 222 }
229 223
230 DEFUN ("listp", Flistp, Slistp, 1, 1, 0 /* 224 DEFUN ("listp", Flistp, Slistp, 1, 1, 0 /*
231 T if OBJECT is a list. This includes nil. 225 T if OBJECT is a list. This includes nil.
232 */ ) 226 */ )
233 (object) 227 (object)
234 Lisp_Object object; 228 Lisp_Object object;
235 { 229 {
236 if (CONSP (object) || NILP (object)) 230 return (CONSP (object) || NILP (object)) ? Qt : Qnil;
237 return Qt;
238 return Qnil;
239 } 231 }
240 232
241 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0 /* 233 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0 /*
242 T if OBJECT is not a list. Lists include nil. 234 T if OBJECT is not a list. Lists include nil.
243 */ ) 235 */ )
244 (object) 236 (object)
245 Lisp_Object object; 237 Lisp_Object object;
246 { 238 {
247 if (CONSP (object) || NILP (object)) 239 return (CONSP (object) || NILP (object)) ? Qnil : Qt;
248 return Qnil;
249 return Qt;
250 } 240 }
251 241
252 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0 /* 242 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0 /*
253 T if OBJECT is a symbol. 243 T if OBJECT is a symbol.
254 */ ) 244 */ )
255 (object) 245 (object)
256 Lisp_Object object; 246 Lisp_Object object;
257 { 247 {
258 if (SYMBOLP (object)) 248 return SYMBOLP (object) ? Qt : Qnil;
259 return Qt;
260 return Qnil;
261 } 249 }
262 250
263 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0 /* 251 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0 /*
264 T if OBJECT is a keyword. 252 T if OBJECT is a keyword.
265 */ ) 253 */ )
266 (object) 254 (object)
267 Lisp_Object object; 255 Lisp_Object object;
268 { 256 {
269 if (KEYWORDP (object)) 257 return KEYWORDP (object) ? Qt : Qnil;
270 return Qt;
271 return Qnil;
272 } 258 }
273 259
274 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0 /* 260 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0 /*
275 T if OBJECT is a vector. 261 T if OBJECT is a vector.
276 */ ) 262 */ )
277 (object) 263 (object)
278 Lisp_Object object; 264 Lisp_Object object;
279 { 265 {
280 if (VECTORP (object)) 266 return VECTORP (object) ? Qt : Qnil;
281 return Qt;
282 return Qnil;
283 } 267 }
284 268
285 DEFUN ("bit-vector-p", Fbit_vector_p, Sbit_vector_p, 1, 1, 0 /* 269 DEFUN ("bit-vector-p", Fbit_vector_p, Sbit_vector_p, 1, 1, 0 /*
286 T if OBJECT is a bit vector. 270 T if OBJECT is a bit vector.
287 */ ) 271 */ )
288 (object) 272 (object)
289 Lisp_Object object; 273 Lisp_Object object;
290 { 274 {
291 if (BIT_VECTORP (object)) 275 return BIT_VECTORP (object) ? Qt : Qnil;
292 return Qt;
293 return Qnil;
294 } 276 }
295 277
296 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0 /* 278 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0 /*
297 T if OBJECT is a string. 279 T if OBJECT is a string.
298 */ ) 280 */ )
299 (object) 281 (object)
300 Lisp_Object object; 282 Lisp_Object object;
301 { 283 {
302 if (STRINGP (object)) 284 return STRINGP (object) ? Qt : Qnil;
303 return Qt;
304 return Qnil;
305 } 285 }
306 286
307 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0 /* 287 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0 /*
308 T if OBJECT is an array (string, vector, or bit vector). 288 T if OBJECT is an array (string, vector, or bit vector).
309 */ ) 289 */ )
310 (object) 290 (object)
311 Lisp_Object object; 291 Lisp_Object object;
312 { 292 {
313 if (VECTORP (object) || STRINGP (object) || BIT_VECTORP (object)) 293 return (VECTORP (object) ||
314 return Qt; 294 STRINGP (object) ||
315 return Qnil; 295 BIT_VECTORP (object))
296 ? Qt : Qnil;
316 } 297 }
317 298
318 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0 /* 299 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0 /*
319 T if OBJECT is a sequence (list or array). 300 T if OBJECT is a sequence (list or array).
320 */ ) 301 */ )
321 (object) 302 (object)
322 Lisp_Object object; 303 Lisp_Object object;
323 { 304 {
324 if (CONSP (object) || NILP (object) 305 return (CONSP (object) ||
325 || VECTORP (object) || STRINGP (object) || BIT_VECTORP (object)) 306 NILP (object) ||
326 return Qt; 307 VECTORP (object) ||
327 return Qnil; 308 STRINGP (object) ||
309 BIT_VECTORP (object))
310 ? Qt : Qnil;
328 } 311 }
329 312
330 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0 /* 313 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0 /*
331 T if OBJECT is a marker (editor pointer). 314 T if OBJECT is a marker (editor pointer).
332 */ ) 315 */ )
333 (object) 316 (object)
334 Lisp_Object object; 317 Lisp_Object object;
335 { 318 {
336 if (MARKERP (object)) 319 return MARKERP (object) ? Qt : Qnil;
337 return Qt;
338 return Qnil;
339 } 320 }
340 321
341 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0 /* 322 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0 /*
342 T if OBJECT is a built-in function. 323 T if OBJECT is a built-in function.
343 */ ) 324 */ )
344 (object) 325 (object)
345 Lisp_Object object; 326 Lisp_Object object;
346 { 327 {
347 if (SUBRP (object)) 328 return SUBRP (object) ? Qt : Qnil;
348 return Qt;
349 return Qnil;
350 } 329 }
351 330
352 DEFUN ("subr-min-args", Fsubr_min_args, Ssubr_min_args, 1, 1, 0 /* 331 DEFUN ("subr-min-args", Fsubr_min_args, Ssubr_min_args, 1, 1, 0 /*
353 Return minimum number of args built-in function SUBR may be called with. 332 Return minimum number of args built-in function SUBR may be called with.
354 */ ) 333 */ )
359 return make_int (XSUBR (subr)->min_args); 338 return make_int (XSUBR (subr)->min_args);
360 } 339 }
361 340
362 DEFUN ("subr-max-args", Fsubr_max_args, Ssubr_max_args, 1, 1, 0 /* 341 DEFUN ("subr-max-args", Fsubr_max_args, Ssubr_max_args, 1, 1, 0 /*
363 Return maximum number of args built-in function SUBR may be called with, 342 Return maximum number of args built-in function SUBR may be called with,
364 or nil if it takes an arbitrary number of arguments (or is a special form). 343 or nil if it takes an arbitrary number of arguments or is a special form.
365 */ ) 344 */ )
366 (subr) 345 (subr)
367 Lisp_Object subr; 346 Lisp_Object subr;
368 { 347 {
369 int nargs; 348 int nargs;
379 t if OBJECT is a byte-compiled function object. 358 t if OBJECT is a byte-compiled function object.
380 */ ) 359 */ )
381 (object) 360 (object)
382 Lisp_Object object; 361 Lisp_Object object;
383 { 362 {
384 if (COMPILED_FUNCTIONP (object)) 363 return COMPILED_FUNCTIONP (object) ? Qt : Qnil;
385 return Qt;
386 return Qnil;
387 } 364 }
388 365
389 366
390 DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 1, 0 /* 367 DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 1, 0 /*
391 t if OBJECT is a character. 368 t if OBJECT is a character.
394 modded with 256 to get the actual character to use. 371 modded with 256 to get the actual character to use.
395 */ ) 372 */ )
396 (object) 373 (object)
397 Lisp_Object object; 374 Lisp_Object object;
398 { 375 {
399 if (CHARP (object)) 376 return CHARP (object) ? Qt : Qnil;
400 return Qt;
401 return Qnil;
402 } 377 }
403 378
404 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0 /* 379 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0 /*
405 t if OBJECT is a character or a string. 380 t if OBJECT is a character or a string.
406 */ ) 381 */ )
407 (object) 382 (object)
408 Lisp_Object object; 383 Lisp_Object object;
409 { 384 {
410 if (CHAR_OR_CHAR_INTP (object) || STRINGP (object)) 385 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
411 return Qt;
412 return Qnil;
413 } 386 }
414 387
415 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0 /* 388 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0 /*
416 t if OBJECT is an integer. 389 t if OBJECT is an integer.
417 */ ) 390 */ )
418 (object) 391 (object)
419 Lisp_Object object; 392 Lisp_Object object;
420 { 393 {
421 if (INTP (object)) 394 return INTP (object) ? Qt : Qnil;
422 return Qt;
423 return Qnil;
424 } 395 }
425 396
426 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 397 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p,
427 1, 1, 0 /* 398 1, 1, 0 /*
428 t if OBJECT is an integer or a marker (editor pointer). 399 t if OBJECT is an integer or a marker (editor pointer).
429 */ ) 400 */ )
430 (object) 401 (object)
431 Lisp_Object object; 402 Lisp_Object object;
432 { 403 {
433 if (INTP (object) || MARKERP (object)) 404 return INTP (object) || MARKERP (object) ? Qt : Qnil;
434 return Qt;
435 return Qnil;
436 } 405 }
437 406
438 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0 /* 407 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0 /*
439 t if OBJECT is a nonnegative integer. 408 t if OBJECT is a nonnegative integer.
440 */ ) 409 */ )
441 (object) 410 (object)
442 Lisp_Object object; 411 Lisp_Object object;
443 { 412 {
444 if (NATNUMP (object)) 413 return NATNUMP (object) ? Qt : Qnil;
445 return Qt;
446 return Qnil;
447 } 414 }
448 415
449 DEFUN ("bitp", Fbitp, Sbitp, 1, 1, 0 /* 416 DEFUN ("bitp", Fbitp, Sbitp, 1, 1, 0 /*
450 t if OBJECT is a bit (0 or 1). 417 t if OBJECT is a bit (0 or 1).
451 */ ) 418 */ )
452 (object) 419 (object)
453 Lisp_Object object; 420 Lisp_Object object;
454 { 421 {
455 if (BITP (object)) 422 return BITP (object) ? Qt : Qnil;
456 return Qt;
457 return Qnil;
458 } 423 }
459 424
460 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0 /* 425 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0 /*
461 t if OBJECT is a number (floating point or integer). 426 t if OBJECT is a number (floating point or integer).
462 */ ) 427 */ )
463 (object) 428 (object)
464 Lisp_Object object; 429 Lisp_Object object;
465 { 430 {
466 if (INT_OR_FLOATP (object)) 431 return INT_OR_FLOATP (object) ? Qt : Qnil;
467 return Qt;
468 return Qnil;
469 } 432 }
470 433
471 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, Snumber_or_marker_p, 1, 1, 0 /* 434 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, Snumber_or_marker_p, 1, 1, 0 /*
472 t if OBJECT is a number or a marker. 435 t if OBJECT is a number or a marker.
473 */ ) 436 */ )
474 (object) 437 (object)
475 Lisp_Object object; 438 Lisp_Object object;
476 { 439 {
477 if (INT_OR_FLOATP (object) 440 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
478 || MARKERP (object))
479 return Qt;
480 return Qnil;
481 } 441 }
482 442
483 #ifdef LISP_FLOAT_TYPE 443 #ifdef LISP_FLOAT_TYPE
484 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0 /* 444 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0 /*
485 t if OBJECT is a floating point number. 445 t if OBJECT is a floating point number.
486 */ ) 446 */ )
487 (object) 447 (object)
488 Lisp_Object object; 448 Lisp_Object object;
489 { 449 {
490 if (FLOATP (object)) 450 return FLOATP (object) ? Qt : Qnil;
491 return Qt;
492 return Qnil;
493 } 451 }
494 #endif /* LISP_FLOAT_TYPE */ 452 #endif /* LISP_FLOAT_TYPE */
495 453
496 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0 /* 454 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0 /*
497 Return a symbol representing the type of OBJECT. 455 Return a symbol representing the type of OBJECT.
498 */ ) 456 */ )
499 (object) 457 (object)
500 Lisp_Object object; 458 Lisp_Object object;
501 { 459 {
502 if (CONSP (object)) 460 if (CONSP (object)) return Qcons;
503 return Qcons; 461 if (SYMBOLP (object)) return Qsymbol;
504 if (SYMBOLP (object)) 462 if (KEYWORDP (object)) return Qkeyword;
505 return Qsymbol; 463 if (INTP (object)) return Qinteger;
506 if (KEYWORDP (object)) 464 if (STRINGP (object)) return Qstring;
507 return Qkeyword; 465 if (VECTORP (object)) return Qvector;
508 if (INTP (object)) 466
509 return Qinteger;
510 if (STRINGP (object))
511 return Qstring;
512 if (VECTORP (object))
513 return Qvector;
514 assert (LRECORDP (object)); 467 assert (LRECORDP (object));
515 return intern (XRECORD_LHEADER (object)->implementation->name); 468 return intern (XRECORD_LHEADER (object)->implementation->name);
516 } 469 }
517 470
518 471
540 Return the car of OBJECT if it is a cons cell, or else nil. 493 Return the car of OBJECT if it is a cons cell, or else nil.
541 */ ) 494 */ )
542 (object) 495 (object)
543 Lisp_Object object; 496 Lisp_Object object;
544 { 497 {
545 if (CONSP (object)) 498 return CONSP (object) ? XCAR (object) : Qnil;
546 return XCAR (object);
547 else
548 return Qnil;
549 } 499 }
550 500
551 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0 /* 501 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0 /*
552 Return the cdr of LIST. If arg is nil, return nil. 502 Return the cdr of LIST. If arg is nil, return nil.
553 Error if arg is not nil and not a cons cell. See also `cdr-safe'. 503 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
570 Return the cdr of OBJECT if it is a cons cell, or else nil. 520 Return the cdr of OBJECT if it is a cons cell, or else nil.
571 */ ) 521 */ )
572 (object) 522 (object)
573 Lisp_Object object; 523 Lisp_Object object;
574 { 524 {
575 if (CONSP (object)) 525 return CONSP (object) ? XCDR (object) : Qnil;
576 return XCDR (object);
577 else
578 return Qnil;
579 } 526 }
580 527
581 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0 /* 528 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0 /*
582 Set the car of CONSCELL to be NEWCAR. Returns NEWCAR. 529 Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.
583 */ ) 530 */ )
617 error if the chain ends up unbound. */ 564 error if the chain ends up unbound. */
618 Lisp_Object 565 Lisp_Object
619 indirect_function (Lisp_Object object, int errorp) 566 indirect_function (Lisp_Object object, int errorp)
620 { 567 {
621 Lisp_Object tortoise = object; 568 Lisp_Object tortoise = object;
622 Lisp_Object hare = object; 569 Lisp_Object hare = object;
623 570
624 for (;;) 571 for (;;)
625 { 572 {
626 if (!SYMBOLP (hare) || UNBOUNDP (hare)) 573 if (!SYMBOLP (hare) || UNBOUNDP (hare))
627 break; 574 break;
962 /**********************************************************************/ 909 /**********************************************************************/
963 910
964 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal }; 911 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
965 912
966 static Lisp_Object 913 static Lisp_Object
967 arithcompare (Lisp_Object num1, Lisp_Object num2, 914 arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison)
968 enum comparison comparison) 915 {
969 {
970 int floatp = 0;
971
972 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num1); 916 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num1);
973 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num2); 917 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num2);
974 918
975 #ifdef LISP_FLOAT_TYPE 919 #ifdef LISP_FLOAT_TYPE
976 if (FLOATP (num1) || FLOATP (num2)) 920 if (FLOATP (num1) || FLOATP (num2))
977 { 921 {
978 double f1, f2; 922 double f1 = (FLOATP (num1)) ? float_data (XFLOAT (num1)) : XINT (num1);
979 923 double f2 = (FLOATP (num2)) ? float_data (XFLOAT (num2)) : XINT (num2);
980 floatp = 1;
981 f1 = (FLOATP (num1)) ? float_data (XFLOAT (num1)) : XINT (num1);
982 f2 = (FLOATP (num2)) ? float_data (XFLOAT (num2)) : XINT (num2);
983 924
984 switch (comparison) 925 switch (comparison)
985 { 926 {
986 case equal: 927 case equal: return f1 == f2 ? Qt : Qnil;
987 if (f1 == f2) 928 case notequal: return f1 != f2 ? Qt : Qnil;
988 return Qt; 929 case less: return f1 < f2 ? Qt : Qnil;
989 return Qnil; 930 case less_or_equal: return f1 <= f2 ? Qt : Qnil;
990 931 case grtr: return f1 > f2 ? Qt : Qnil;
991 case notequal: 932 case grtr_or_equal: return f1 >= f2 ? Qt : Qnil;
992 if (f1 != f2) 933 }
993 return Qt;
994 return Qnil;
995
996 case less:
997 if (f1 < f2)
998 return Qt;
999 return Qnil;
1000
1001 case less_or_equal:
1002 if (f1 <= f2)
1003 return Qt;
1004 return Qnil;
1005
1006 case grtr:
1007 if (f1 > f2)
1008 return Qt;
1009 return Qnil;
1010
1011 case grtr_or_equal:
1012 if (f1 >= f2)
1013 return Qt;
1014 return Qnil;
1015 }
1016 } 934 }
1017 #endif /* LISP_FLOAT_TYPE */ 935 #endif /* LISP_FLOAT_TYPE */
1018 else 936
1019 { 937 switch (comparison)
1020 switch (comparison) 938 {
1021 { 939 case equal: return XINT (num1) == XINT (num2) ? Qt : Qnil;
1022 case equal: 940 case notequal: return XINT (num1) != XINT (num2) ? Qt : Qnil;
1023 if (XINT (num1) == XINT (num2)) 941 case less: return XINT (num1) < XINT (num2) ? Qt : Qnil;
1024 return Qt; 942 case less_or_equal: return XINT (num1) <= XINT (num2) ? Qt : Qnil;
1025 return Qnil; 943 case grtr: return XINT (num1) > XINT (num2) ? Qt : Qnil;
1026 944 case grtr_or_equal: return XINT (num1) >= XINT (num2) ? Qt : Qnil;
1027 case notequal: 945 }
1028 if (XINT (num1) != XINT (num2)) 946
1029 return Qt;
1030 return Qnil;
1031
1032 case less:
1033 if (XINT (num1) < XINT (num2))
1034 return Qt;
1035 return Qnil;
1036
1037 case less_or_equal:
1038 if (XINT (num1) <= XINT (num2))
1039 return Qt;
1040 return Qnil;
1041
1042 case grtr:
1043 if (XINT (num1) > XINT (num2))
1044 return Qt;
1045 return Qnil;
1046
1047 case grtr_or_equal:
1048 if (XINT (num1) >= XINT (num2))
1049 return Qt;
1050 return Qnil;
1051 }
1052 }
1053 abort (); 947 abort ();
1054 return Qnil; /* suppress compiler warning */ 948 return Qnil; /* suppress compiler warning */
1055 } 949 }
1056 950
1057 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0 /* 951 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0 /*
1062 { 956 {
1063 return arithcompare (num1, num2, equal); 957 return arithcompare (num1, num2, equal);
1064 } 958 }
1065 959
1066 DEFUN ("<", Flss, Slss, 2, 2, 0 /* 960 DEFUN ("<", Flss, Slss, 2, 2, 0 /*
1067 T if first arg is less than second arg. Both must be numbers or markers. 961 T if first arg is less than second arg.
962 Both must be numbers or markers.
1068 */ ) 963 */ )
1069 (num1, num2) 964 (num1, num2)
1070 Lisp_Object num1, num2; 965 Lisp_Object num1, num2;
1071 { 966 {
1072 return arithcompare (num1, num2, less); 967 return arithcompare (num1, num2, less);
1073 } 968 }
1074 969
1075 DEFUN (">", Fgtr, Sgtr, 2, 2, 0 /* 970 DEFUN (">", Fgtr, Sgtr, 2, 2, 0 /*
1076 T if first arg is greater than second arg. Both must be numbers or markers. 971 T if first arg is greater than second arg.
972 Both must be numbers or markers.
1077 */ ) 973 */ )
1078 (num1, num2) 974 (num1, num2)
1079 Lisp_Object num1, num2; 975 Lisp_Object num1, num2;
1080 { 976 {
1081 return arithcompare (num1, num2, grtr); 977 return arithcompare (num1, num2, grtr);
1100 { 996 {
1101 return arithcompare (num1, num2, grtr_or_equal); 997 return arithcompare (num1, num2, grtr_or_equal);
1102 } 998 }
1103 999
1104 DEFUN ("/=", Fneq, Sneq, 2, 2, 0 /* 1000 DEFUN ("/=", Fneq, Sneq, 2, 2, 0 /*
1105 T if first arg is not equal to second arg. Both must be numbers or markers. 1001 T if first arg is not equal to second arg.
1002 Both must be numbers or markers.
1106 */ ) 1003 */ )
1107 (num1, num2) 1004 (num1, num2)
1108 Lisp_Object num1, num2; 1005 Lisp_Object num1, num2;
1109 { 1006 {
1110 return arithcompare (num1, num2, notequal); 1007 return arithcompare (num1, num2, notequal);
1118 { 1015 {
1119 CHECK_INT_OR_FLOAT (number); 1016 CHECK_INT_OR_FLOAT (number);
1120 1017
1121 #ifdef LISP_FLOAT_TYPE 1018 #ifdef LISP_FLOAT_TYPE
1122 if (FLOATP (number)) 1019 if (FLOATP (number))
1123 { 1020 return (float_data (XFLOAT (number)) == 0.0) ? Qt : Qnil;
1124 if (float_data (XFLOAT (number)) == 0.0)
1125 return Qt;
1126 return Qnil;
1127 }
1128 #endif /* LISP_FLOAT_TYPE */ 1021 #endif /* LISP_FLOAT_TYPE */
1129 1022
1130 if (XINT (number) == 0) 1023 return (XINT (number) == 0) ? Qt : Qnil;
1131 return Qt;
1132 return Qnil;
1133 } 1024 }
1134 1025
1135 /* Convert between a 32-bit value and a cons of two 16-bit values. 1026 /* Convert between a 32-bit value and a cons of two 16-bit values.
1136 This is used to pass 32-bit integers to and from the user. 1027 This is used to pass 32-bit integers to and from the user.
1137 Use time_to_lisp() and lisp_to_time() for time values. 1028 Use time_to_lisp() and lisp_to_time() for time values.
1202 { 1093 {
1203 Lisp_Object value; 1094 Lisp_Object value;
1204 char *p; 1095 char *p;
1205 CHECK_STRING (string); 1096 CHECK_STRING (string);
1206 1097
1207 p = (char *) string_data (XSTRING (string)); 1098 p = (char *) XSTRING_DATA (string);
1208 /* Skip any whitespace at the front of the number. Some versions of 1099 /* Skip any whitespace at the front of the number. Some versions of
1209 atoi do this anyway, so we might as well make Emacs lisp consistent. */ 1100 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1210 while (*p == ' ' || *p == '\t') 1101 while (*p == ' ' || *p == '\t')
1211 p++; 1102 p++;
1212 1103
1226 1117
1227 enum arithop 1118 enum arithop
1228 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin }; 1119 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
1229 1120
1230 #ifdef LISP_FLOAT_TYPE 1121 #ifdef LISP_FLOAT_TYPE
1231 static Lisp_Object float_arith_driver (double accum, int argnum,
1232 enum arithop code,
1233 int nargs, Lisp_Object *args);
1234 #endif
1235
1236
1237 static Lisp_Object
1238 arith_driver (enum arithop code, int nargs, Lisp_Object *args)
1239 {
1240 Lisp_Object val;
1241 REGISTER int argnum;
1242 REGISTER EMACS_INT accum = 0;
1243 REGISTER EMACS_INT next;
1244
1245 switch (code)
1246 {
1247 case Alogior:
1248 case Alogxor:
1249 case Aadd:
1250 case Asub:
1251 accum = 0; break;
1252 case Amult:
1253 accum = 1; break;
1254 case Alogand:
1255 accum = -1; break;
1256 case Adiv:
1257 case Amax:
1258 case Amin:
1259 accum = 0;
1260 break;
1261 default:
1262 abort ();
1263 }
1264
1265 for (argnum = 0; argnum < nargs; argnum++)
1266 {
1267 val = args[argnum]; /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
1268 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
1269
1270 #ifdef LISP_FLOAT_TYPE
1271 if (FLOATP (val)) /* time to do serious math */
1272 return (float_arith_driver ((double) accum, argnum, code,
1273 nargs, args));
1274 #endif /* LISP_FLOAT_TYPE */
1275 args[argnum] = val; /* runs into a compiler bug. */
1276 next = XINT (args[argnum]);
1277 switch (code)
1278 {
1279 case Aadd: accum += next; break;
1280 case Asub:
1281 if (!argnum && nargs != 1)
1282 next = - next;
1283 accum -= next;
1284 break;
1285 case Amult: accum *= next; break;
1286 case Adiv:
1287 if (!argnum) accum = next;
1288 else
1289 {
1290 if (next == 0)
1291 Fsignal (Qarith_error, Qnil);
1292 accum /= next;
1293 }
1294 break;
1295 case Alogand: accum &= next; break;
1296 case Alogior: accum |= next; break;
1297 case Alogxor: accum ^= next; break;
1298 case Amax: if (!argnum || next > accum) accum = next; break;
1299 case Amin: if (!argnum || next < accum) accum = next; break;
1300 }
1301 }
1302
1303 XSETINT (val, accum);
1304 return val;
1305 }
1306
1307 #ifdef LISP_FLOAT_TYPE
1308 static Lisp_Object 1122 static Lisp_Object
1309 float_arith_driver (double accum, int argnum, enum arithop code, int nargs, 1123 float_arith_driver (double accum, int argnum, enum arithop code, int nargs,
1310 Lisp_Object *args) 1124 Lisp_Object *args)
1311 { 1125 {
1312 REGISTER Lisp_Object val; 1126 REGISTER Lisp_Object val;
1313 double next; 1127 double next;
1314 1128
1315 for (; argnum < nargs; argnum++) 1129 for (; argnum < nargs; argnum++)
1316 { 1130 {
1317 val = args[argnum]; /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */ 1131 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
1132 val = args[argnum];
1318 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val); 1133 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
1319 1134
1320 if (FLOATP (val)) 1135 if (FLOATP (val))
1321 { 1136 {
1322 next = float_data (XFLOAT (val)); 1137 next = float_data (XFLOAT (val));
1366 1181
1367 return make_float (accum); 1182 return make_float (accum);
1368 } 1183 }
1369 #endif /* LISP_FLOAT_TYPE */ 1184 #endif /* LISP_FLOAT_TYPE */
1370 1185
1186 static Lisp_Object
1187 arith_driver (enum arithop code, int nargs, Lisp_Object *args)
1188 {
1189 Lisp_Object val;
1190 REGISTER int argnum;
1191 REGISTER EMACS_INT accum = 0;
1192 REGISTER EMACS_INT next;
1193
1194 switch (code)
1195 {
1196 case Alogior:
1197 case Alogxor:
1198 case Aadd:
1199 case Asub:
1200 accum = 0; break;
1201 case Amult:
1202 accum = 1; break;
1203 case Alogand:
1204 accum = -1; break;
1205 case Adiv:
1206 case Amax:
1207 case Amin:
1208 accum = 0; break;
1209 default:
1210 abort ();
1211 }
1212
1213 for (argnum = 0; argnum < nargs; argnum++)
1214 {
1215 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
1216 val = args[argnum];
1217 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
1218
1219 #ifdef LISP_FLOAT_TYPE
1220 if (FLOATP (val)) /* time to do serious math */
1221 return (float_arith_driver ((double) accum, argnum, code,
1222 nargs, args));
1223 #endif /* LISP_FLOAT_TYPE */
1224 args[argnum] = val; /* runs into a compiler bug. */
1225 next = XINT (args[argnum]);
1226 switch (code)
1227 {
1228 case Aadd: accum += next; break;
1229 case Asub:
1230 if (!argnum && nargs != 1)
1231 next = - next;
1232 accum -= next;
1233 break;
1234 case Amult: accum *= next; break;
1235 case Adiv:
1236 if (!argnum) accum = next;
1237 else
1238 {
1239 if (next == 0)
1240 Fsignal (Qarith_error, Qnil);
1241 accum /= next;
1242 }
1243 break;
1244 case Alogand: accum &= next; break;
1245 case Alogior: accum |= next; break;
1246 case Alogxor: accum ^= next; break;
1247 case Amax: if (!argnum || next > accum) accum = next; break;
1248 case Amin: if (!argnum || next < accum) accum = next; break;
1249 }
1250 }
1251
1252 XSETINT (val, accum);
1253 return val;
1254 }
1255
1371 DEFUN ("+", Fplus, Splus, 0, MANY, 0 /* 1256 DEFUN ("+", Fplus, Splus, 0, MANY, 0 /*
1372 Return sum of any number of arguments, which are numbers or markers. 1257 Return sum of any number of arguments.
1258 The arguments should all be numbers or markers.
1373 */ ) 1259 */ )
1374 (nargs, args) 1260 (nargs, args)
1375 int nargs; 1261 int nargs;
1376 Lisp_Object *args; 1262 Lisp_Object *args;
1377 { 1263 {
1389 { 1275 {
1390 return arith_driver (Asub, nargs, args); 1276 return arith_driver (Asub, nargs, args);
1391 } 1277 }
1392 1278
1393 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0 /* 1279 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0 /*
1394 Return product of any number of arguments, which are numbers or markers. 1280 Return product of any number of arguments.
1281 The arguments should all be numbers or markers.
1395 */ ) 1282 */ )
1396 (nargs, args) 1283 (nargs, args)
1397 int nargs; 1284 int nargs;
1398 Lisp_Object *args; 1285 Lisp_Object *args;
1399 { 1286 {
1493 return (make_int (i1)); 1380 return (make_int (i1));
1494 } 1381 }
1495 1382
1496 1383
1497 DEFUN ("max", Fmax, Smax, 1, MANY, 0 /* 1384 DEFUN ("max", Fmax, Smax, 1, MANY, 0 /*
1498 Return largest of all the arguments (which must be numbers or markers). 1385 Return largest of all the arguments.
1386 All arguments must be numbers or markers.
1499 The value is always a number; markers are converted to numbers. 1387 The value is always a number; markers are converted to numbers.
1500 */ ) 1388 */ )
1501 (nargs, args) 1389 (nargs, args)
1502 int nargs; 1390 int nargs;
1503 Lisp_Object *args; 1391 Lisp_Object *args;
1504 { 1392 {
1505 return arith_driver (Amax, nargs, args); 1393 return arith_driver (Amax, nargs, args);
1506 } 1394 }
1507 1395
1508 DEFUN ("min", Fmin, Smin, 1, MANY, 0 /* 1396 DEFUN ("min", Fmin, Smin, 1, MANY, 0 /*
1509 Return smallest of all the arguments (which must be numbers or markers). 1397 Return smallest of all the arguments.
1398 All arguments must be numbers or markers.
1510 The value is always a number; markers are converted to numbers. 1399 The value is always a number; markers are converted to numbers.
1511 */ ) 1400 */ )
1512 (nargs, args) 1401 (nargs, args)
1513 int nargs; 1402 int nargs;
1514 Lisp_Object *args; 1403 Lisp_Object *args;
1558 Lisp_Object value, count; 1447 Lisp_Object value, count;
1559 { 1448 {
1560 CHECK_INT_COERCE_CHAR (value); 1449 CHECK_INT_COERCE_CHAR (value);
1561 CHECK_INT (count); 1450 CHECK_INT (count);
1562 1451
1563 if (XINT (count) > 0) 1452 return make_int (XINT (count) > 0 ?
1564 return (make_int (XINT (value) << XINT (count))); 1453 XINT (value) << XINT (count) :
1565 else 1454 XINT (value) >> -XINT (count));
1566 return (make_int (XINT (value) >> -XINT (count)));
1567 } 1455 }
1568 1456
1569 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0 /* 1457 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0 /*
1570 Return VALUE with its bits shifted left by COUNT. 1458 Return VALUE with its bits shifted left by COUNT.
1571 If COUNT is negative, shifting is actually to the right. 1459 If COUNT is negative, shifting is actually to the right.
1679 weak_list_equal (Lisp_Object o1, Lisp_Object o2, int depth) 1567 weak_list_equal (Lisp_Object o1, Lisp_Object o2, int depth)
1680 { 1568 {
1681 struct weak_list *w1 = XWEAK_LIST (o1); 1569 struct weak_list *w1 = XWEAK_LIST (o1);
1682 struct weak_list *w2 = XWEAK_LIST (o2); 1570 struct weak_list *w2 = XWEAK_LIST (o2);
1683 1571
1684 if (w1->type != w2->type || 1572 return (w1->type != w2->type &&
1685 !internal_equal (w1->list, w2->list, depth + 1)) 1573 internal_equal (w1->list, w2->list, depth + 1));
1686 return 0;
1687 else
1688 return 1;
1689 } 1574 }
1690 1575
1691 static unsigned long 1576 static unsigned long
1692 weak_list_hash (Lisp_Object obj, int depth) 1577 weak_list_hash (Lisp_Object obj, int depth)
1693 { 1578 {
1960 1845
1961 static enum weak_list_type 1846 static enum weak_list_type
1962 decode_weak_list_type (Lisp_Object symbol) 1847 decode_weak_list_type (Lisp_Object symbol)
1963 { 1848 {
1964 CHECK_SYMBOL (symbol); 1849 CHECK_SYMBOL (symbol);
1965 if (EQ (symbol, Qsimple)) 1850 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
1966 return WEAK_LIST_SIMPLE; 1851 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
1967 if (EQ (symbol, Qassoc)) 1852 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
1968 return WEAK_LIST_ASSOC; 1853 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
1969 if (EQ (symbol, Qkey_assoc))
1970 return WEAK_LIST_KEY_ASSOC;
1971 if (EQ (symbol, Qvalue_assoc))
1972 return WEAK_LIST_VALUE_ASSOC;
1973 1854
1974 signal_simple_error ("Invalid weak list type", symbol); 1855 signal_simple_error ("Invalid weak list type", symbol);
1975 return WEAK_LIST_SIMPLE; /* not reached */ 1856 return WEAK_LIST_SIMPLE; /* not reached */
1976 } 1857 }
1977 1858
1978 static Lisp_Object 1859 static Lisp_Object
1979 encode_weak_list_type (enum weak_list_type type) 1860 encode_weak_list_type (enum weak_list_type type)
1980 { 1861 {
1981 switch (type) 1862 switch (type)
1982 { 1863 {
1983 case WEAK_LIST_SIMPLE: 1864 case WEAK_LIST_SIMPLE: return Qsimple;
1984 return Qsimple; 1865 case WEAK_LIST_ASSOC: return Qassoc;
1985 case WEAK_LIST_ASSOC: 1866 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
1986 return Qassoc; 1867 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
1987 case WEAK_LIST_KEY_ASSOC:
1988 return Qkey_assoc;
1989 case WEAK_LIST_VALUE_ASSOC:
1990 return Qvalue_assoc;
1991 default: 1868 default:
1992 abort (); 1869 abort ();
1993 } 1870 }
1994 1871
1995 return Qnil; 1872 return Qnil; /* not reached */
1996 } 1873 }
1997 1874
1998 DEFUN ("weak-list-p", Fweak_list_p, Sweak_list_p, 1, 1, 0 /* 1875 DEFUN ("weak-list-p", Fweak_list_p, Sweak_list_p, 1, 1, 0 /*
1999 Return non-nil if OBJECT is a weak list. 1876 Return non-nil if OBJECT is a weak list.
2000 */ ) 1877 */ )