diff options
| author | Ken Raeburn | 2001-10-16 09:09:51 +0000 |
|---|---|---|
| committer | Ken Raeburn | 2001-10-16 09:09:51 +0000 |
| commit | f3fbd1553534bb85c75baf891c0ca9aaa4c3fa6f (patch) | |
| tree | 43eb51ff0ca4af1705387403827ef210098f2da8 /src/lisp.h | |
| parent | 018ba359ab456f6a43f3acea0c15df616aa0ad02 (diff) | |
| download | emacs-f3fbd1553534bb85c75baf891c0ca9aaa4c3fa6f.tar.gz emacs-f3fbd1553534bb85c75baf891c0ca9aaa4c3fa6f.zip | |
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
with lisp system changes.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/src/lisp.h b/src/lisp.h index add5312578b..2cb7a1fcc7f 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -248,6 +248,16 @@ Lisp_Object; | |||
| 248 | 248 | ||
| 249 | #endif /* WORDS_BIG_ENDIAN */ | 249 | #endif /* WORDS_BIG_ENDIAN */ |
| 250 | 250 | ||
| 251 | #ifdef __GNUC__ | ||
| 252 | static __inline__ Lisp_Object | ||
| 253 | LISP_MAKE_RVALUE (Lisp_Object o) | ||
| 254 | { | ||
| 255 | return o; | ||
| 256 | } | ||
| 257 | #else | ||
| 258 | #define LISP_MAKE_RVALUE(o) (o) /* XXX - keeps arg as rvalue. */ | ||
| 259 | #endif | ||
| 260 | |||
| 251 | #endif /* NO_UNION_TYPE */ | 261 | #endif /* NO_UNION_TYPE */ |
| 252 | 262 | ||
| 253 | 263 | ||
| @@ -255,6 +265,7 @@ Lisp_Object; | |||
| 255 | 265 | ||
| 256 | #ifdef NO_UNION_TYPE | 266 | #ifdef NO_UNION_TYPE |
| 257 | #define Lisp_Object EMACS_INT | 267 | #define Lisp_Object EMACS_INT |
| 268 | #define LISP_MAKE_RVALUE(o) (0+(o)) | ||
| 258 | #endif /* NO_UNION_TYPE */ | 269 | #endif /* NO_UNION_TYPE */ |
| 259 | 270 | ||
| 260 | #ifndef VALMASK | 271 | #ifndef VALMASK |
| @@ -616,14 +627,43 @@ struct Lisp_Cons | |||
| 616 | }; | 627 | }; |
| 617 | 628 | ||
| 618 | /* Take the car or cdr of something known to be a cons cell. */ | 629 | /* Take the car or cdr of something known to be a cons cell. */ |
| 630 | /* The _AS_LVALUE macros shouldn't be used outside of the minimal set | ||
| 631 | of code that has to know what a cons cell looks like. Other code not | ||
| 632 | part of the basic lisp implementation should assume that the car and cdr | ||
| 633 | fields are not accessible as lvalues. (What if we want to switch to | ||
| 634 | a copying collector someday? Cached cons cell field addresses may be | ||
| 635 | invalidated at arbitrary points.) */ | ||
| 619 | #ifdef HIDE_LISP_IMPLEMENTATION | 636 | #ifdef HIDE_LISP_IMPLEMENTATION |
| 620 | #define XCAR(c) (XCONS ((c))->car_) | 637 | #define XCAR_AS_LVALUE(c) (XCONS ((c))->car_) |
| 621 | #define XCDR(c) (XCONS ((c))->cdr_) | 638 | #define XCDR_AS_LVALUE(c) (XCONS ((c))->cdr_) |
| 622 | #else | 639 | #else |
| 623 | #define XCAR(c) (XCONS ((c))->car) | 640 | #define XCAR_AS_LVALUE(c) (XCONS ((c))->car) |
| 624 | #define XCDR(c) (XCONS ((c))->cdr) | 641 | #define XCDR_AS_LVALUE(c) (XCONS ((c))->cdr) |
| 625 | #endif | 642 | #endif |
| 626 | 643 | ||
| 644 | /* Okay, we're not quite ready to turn this on yet. A few files still | ||
| 645 | need to be updated and tested. */ | ||
| 646 | #undef LISP_MAKE_RVALUE | ||
| 647 | #define LISP_MAKE_RVALUE(x) (x) | ||
| 648 | |||
| 649 | /* Use these from normal code. */ | ||
| 650 | #define XCAR(c) LISP_MAKE_RVALUE(XCAR_AS_LVALUE(c)) | ||
| 651 | #define XCDR(c) LISP_MAKE_RVALUE(XCDR_AS_LVALUE(c)) | ||
| 652 | |||
| 653 | /* Use these to set the fields of a cons cell. | ||
| 654 | |||
| 655 | Note that both arguments may refer to the same object, so 'n' | ||
| 656 | should not be read after 'c' is first modified. Also, neither | ||
| 657 | argument should be evaluated more than once; side effects are | ||
| 658 | especially common in the second argument. */ | ||
| 659 | #define XSETCAR(c,n) (XCAR_AS_LVALUE(c) = (n)) | ||
| 660 | #define XSETCDR(c,n) (XCDR_AS_LVALUE(c) = (n)) | ||
| 661 | |||
| 662 | /* For performance: Fast storage of positive integers into the | ||
| 663 | fields of a cons cell. See above caveats. */ | ||
| 664 | #define XSETCARFASTINT(c,n) XSETFASTINT(XCAR_AS_LVALUE(c),(n)) | ||
| 665 | #define XSETCDRFASTINT(c,n) XSETFASTINT(XCDR_AS_LVALUE(c),(n)) | ||
| 666 | |||
| 627 | /* Take the car or cdr of something whose type is not known. */ | 667 | /* Take the car or cdr of something whose type is not known. */ |
| 628 | #define CAR(c) \ | 668 | #define CAR(c) \ |
| 629 | (CONSP ((c)) ? XCAR ((c)) \ | 669 | (CONSP ((c)) ? XCAR ((c)) \ |
| @@ -1474,6 +1514,22 @@ typedef unsigned char UCHAR; | |||
| 1474 | #define CHECK_OVERLAY(x, i) \ | 1514 | #define CHECK_OVERLAY(x, i) \ |
| 1475 | do { if (!OVERLAYP ((x))) x = wrong_type_argument (Qoverlayp, (x));} while (0) | 1515 | do { if (!OVERLAYP ((x))) x = wrong_type_argument (Qoverlayp, (x));} while (0) |
| 1476 | 1516 | ||
| 1517 | /* Since we can't assign directly to the CAR or CDR fields of a cons | ||
| 1518 | cell, use these when checking that those fields contain numbers. */ | ||
| 1519 | #define CHECK_NUMBER_CAR(x, i) \ | ||
| 1520 | do { \ | ||
| 1521 | Lisp_Object tmp = XCAR (x); \ | ||
| 1522 | CHECK_NUMBER (tmp, (i)); \ | ||
| 1523 | XSETCAR ((x), tmp); \ | ||
| 1524 | } while (0) | ||
| 1525 | |||
| 1526 | #define CHECK_NUMBER_CDR(x, i) \ | ||
| 1527 | do { \ | ||
| 1528 | Lisp_Object tmp = XCDR (x); \ | ||
| 1529 | CHECK_NUMBER (tmp, (i)); \ | ||
| 1530 | XSETCDR ((x), tmp); \ | ||
| 1531 | } while (0) | ||
| 1532 | |||
| 1477 | /* Cast pointers to this type to compare them. Some machines want int. */ | 1533 | /* Cast pointers to this type to compare them. Some machines want int. */ |
| 1478 | #ifndef PNTR_COMPARISON_TYPE | 1534 | #ifndef PNTR_COMPARISON_TYPE |
| 1479 | #define PNTR_COMPARISON_TYPE EMACS_UINT | 1535 | #define PNTR_COMPARISON_TYPE EMACS_UINT |