comparison src/data.c @ 5752:70a3f4ff8da8

Improve coding style, variable names, data.c, sequence.c src/ChangeLog addition: 2013-08-05 Aidan Kehoe <kehoea@parhasard.net> * data.c: * data.c (Fcar): * data.c (Fcdr): * data.c (Fmake_weak_box): * data.c (Fweak_box_ref): * data.c (init_marking_ephemerons): * data.c (continue_marking_ephemerons): * data.c (finish_marking_ephemerons): * data.c (prune_ephemerons): * data.c (zap_finalize_list): * data.c (ephemeron_equal): * data.c (ephemeron_hash): * data.c (Fmake_ephemeron): * data.c (Fephemeron_ref): * data.c (Fephemeronp): * sequence.c: * sequence.c (Fcopy_tree): * sequence.c (Freplace): Improve coding style here; #'car and #'cdr accept lists, not just cons cells, update their argument names to reflect that. Follow coding conventions in the weak box and ephemeron code. Don't needlessly abbreviate in copy-tree, use argument names from Common Lisp in #'merge and #'replace. Document ALIST better in #'nsublis, #'sublis.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 05 Aug 2013 17:20:16 +0100
parents 3192994c49ca
children 427a72c6ee17
comparison
equal deleted inserted replaced
5751:2b8edd304c2b 5752:70a3f4ff8da8
570 570
571 571
572 /* Extract and set components of lists */ 572 /* Extract and set components of lists */
573 573
574 DEFUN ("car", Fcar, 1, 1, 0, /* 574 DEFUN ("car", Fcar, 1, 1, 0, /*
575 Return the car of CONS. If CONS is nil, return nil. 575 Return the car of LIST. If LIST is nil, return nil.
576 The car of a list or a dotted pair is its first element. 576 The car of a list or a dotted pair is its first element.
577 577
578 Error if CONS is not nil and not a cons cell. See also `car-safe'. 578 Error if LIST is not nil and not a cons cell. See also `car-safe'.
579 */ 579 */
580 (cons)) 580 (list))
581 { 581 {
582 while (1) 582 while (1)
583 { 583 {
584 if (CONSP (cons)) 584 if (CONSP (list))
585 return XCAR (cons); 585 return XCAR (list);
586 else if (NILP (cons)) 586 else if (NILP (list))
587 return Qnil; 587 return Qnil;
588 else 588 else
589 cons = wrong_type_argument (Qlistp, cons); 589 list = wrong_type_argument (Qlistp, list);
590 } 590 }
591 } 591 }
592 592
593 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /* 593 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
594 Return the car of OBJECT if it is a cons cell, or else nil. 594 Return the car of OBJECT if it is a cons cell, or else nil.
597 { 597 {
598 return CONSP (object) ? XCAR (object) : Qnil; 598 return CONSP (object) ? XCAR (object) : Qnil;
599 } 599 }
600 600
601 DEFUN ("cdr", Fcdr, 1, 1, 0, /* 601 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
602 Return the cdr of CONS. If CONS is nil, return nil. 602 Return the cdr of LIST. If LIST is nil, return nil.
603 The cdr of a list is the list without its first element. The cdr of a 603 The cdr of a list is the list without its first element. The cdr of a
604 dotted pair (A . B) is the second element, B. 604 dotted pair (A . B) is the second element, B.
605 605
606 Error if arg is not nil and not a cons cell. See also `cdr-safe'. 606 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
607 */ 607 */
608 (cons)) 608 (list))
609 { 609 {
610 while (1) 610 while (1)
611 { 611 {
612 if (CONSP (cons)) 612 if (CONSP (list))
613 return XCDR (cons); 613 return XCDR (list);
614 else if (NILP (cons)) 614 else if (NILP (list))
615 return Qnil; 615 return Qnil;
616 else 616 else
617 cons = wrong_type_argument (Qlistp, cons); 617 list = wrong_type_argument (Qlistp, list);
618 } 618 }
619 } 619 }
620 620
621 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /* 621 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
622 Return the cdr of OBJECT if it is a cons cell, else nil. 622 Return the cdr of OBJECT if it is a cons cell, else nil.
3119 reachability of CONTENTS. When CONTENTS is garbage-collected, 3119 reachability of CONTENTS. When CONTENTS is garbage-collected,
3120 `weak-box-ref' will return NIL. 3120 `weak-box-ref' will return NIL.
3121 */ 3121 */
3122 (value)) 3122 (value))
3123 { 3123 {
3124 return make_weak_box(value); 3124 return make_weak_box (value);
3125 } 3125 }
3126 3126
3127 DEFUN ("weak-box-ref", Fweak_box_ref, 1, 1, 0, /* 3127 DEFUN ("weak-box-ref", Fweak_box_ref, 1, 1, 0, /*
3128 Return the contents of weak box WEAK-BOX. 3128 Return the contents of weak box WEAK-BOX.
3129 If the contents have been GCed, return NIL. 3129 If the contents have been GCed, return NIL.
3130 */ 3130 */
3131 (wb)) 3131 (weak_box))
3132 { 3132 {
3133 return XWEAK_BOX (wb)->value; 3133 return XWEAK_BOX (weak_box)->value;
3134 } 3134 }
3135 3135
3136 DEFUN ("weak-box-p", Fweak_boxp, 1, 1, 0, /* 3136 DEFUN ("weak-box-p", Fweak_boxp, 1, 1, 0, /*
3137 Return non-nil if OBJECT is a weak box. 3137 Return non-nil if OBJECT is a weak box.
3138 */ 3138 */
3159 static Lisp_Object Vall_ephemerons; /* Gemarke es niemals ever!!! */ 3159 static Lisp_Object Vall_ephemerons; /* Gemarke es niemals ever!!! */
3160 static Lisp_Object Vnew_all_ephemerons; 3160 static Lisp_Object Vnew_all_ephemerons;
3161 static Lisp_Object Vfinalize_list; 3161 static Lisp_Object Vfinalize_list;
3162 3162
3163 void 3163 void
3164 init_marking_ephemerons(void) 3164 init_marking_ephemerons (void)
3165 { 3165 {
3166 Vnew_all_ephemerons = Qnil; 3166 Vnew_all_ephemerons = Qnil;
3167 } 3167 }
3168 3168
3169 /* Move all live ephemerons with live keys over to 3169 /* Move all live ephemerons with live keys over to
3170 * Vnew_all_ephemerons, marking the values and finalizers along the 3170 * Vnew_all_ephemerons, marking the values and finalizers along the
3171 * way. */ 3171 * way. */
3172 3172
3173 int 3173 int
3174 continue_marking_ephemerons(void) 3174 continue_marking_ephemerons (void)
3175 { 3175 {
3176 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil; 3176 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
3177 int did_mark = 0; 3177 int did_mark = 0;
3178 3178
3179 while (!NILP (rest)) 3179 while (!NILP (rest))
3215 * Well, almost: we still need to run the finalizers, so we need to 3215 * Well, almost: we still need to run the finalizers, so we need to
3216 * resurrect them. 3216 * resurrect them.
3217 */ 3217 */
3218 3218
3219 int 3219 int
3220 finish_marking_ephemerons(void) 3220 finish_marking_ephemerons (void)
3221 { 3221 {
3222 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil; 3222 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
3223 int did_mark = 0; 3223 int did_mark = 0;
3224 3224
3225 while (! NILP (rest)) 3225 while (! NILP (rest))
3262 3262
3263 return did_mark; 3263 return did_mark;
3264 } 3264 }
3265 3265
3266 void 3266 void
3267 prune_ephemerons(void) 3267 prune_ephemerons (void)
3268 { 3268 {
3269 Vall_ephemerons = Vnew_all_ephemerons; 3269 Vall_ephemerons = Vnew_all_ephemerons;
3270 } 3270 }
3271 3271
3272 Lisp_Object 3272 Lisp_Object
3273 zap_finalize_list(void) 3273 zap_finalize_list (void)
3274 { 3274 {
3275 Lisp_Object finalizers = Vfinalize_list; 3275 Lisp_Object finalizers = Vfinalize_list;
3276 3276
3277 Vfinalize_list = Qnil; 3277 Vfinalize_list = Qnil;
3278 3278
3304 3304
3305 static int 3305 static int
3306 ephemeron_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) 3306 ephemeron_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase)
3307 { 3307 {
3308 return 3308 return
3309 internal_equal_0 (XEPHEMERON_REF (obj1), XEPHEMERON_REF(obj2), depth + 1, 3309 internal_equal_0 (XEPHEMERON_REF (obj1), XEPHEMERON_REF (obj2),
3310 foldcase); 3310 depth + 1, foldcase);
3311 } 3311 }
3312 3312
3313 static Hashcode 3313 static Hashcode
3314 ephemeron_hash(Lisp_Object obj, int depth, Boolint equalp) 3314 ephemeron_hash (Lisp_Object obj, int depth, Boolint equalp)
3315 { 3315 {
3316 return internal_hash (XEPHEMERON_REF (obj), depth + 1, equalp); 3316 return internal_hash (XEPHEMERON_REF (obj), depth + 1, equalp);
3317 } 3317 }
3318 3318
3319 Lisp_Object 3319 Lisp_Object
3343 } 3343 }
3344 3344
3345 /* Ephemerons are special cases in the KKCC mark algorithm, so nothing 3345 /* Ephemerons are special cases in the KKCC mark algorithm, so nothing
3346 is marked here. */ 3346 is marked here. */
3347 static const struct memory_description ephemeron_description[] = { 3347 static const struct memory_description ephemeron_description[] = {
3348 { XD_LISP_OBJECT, offsetof(struct ephemeron, key), 3348 { XD_LISP_OBJECT, offsetof (struct ephemeron, key),
3349 0, { 0 }, XD_FLAG_NO_KKCC }, 3349 0, { 0 }, XD_FLAG_NO_KKCC },
3350 { XD_LISP_OBJECT, offsetof(struct ephemeron, cons_chain), 3350 { XD_LISP_OBJECT, offsetof (struct ephemeron, cons_chain),
3351 0, { 0 }, XD_FLAG_NO_KKCC }, 3351 0, { 0 }, XD_FLAG_NO_KKCC },
3352 { XD_LISP_OBJECT, offsetof(struct ephemeron, value), 3352 { XD_LISP_OBJECT, offsetof (struct ephemeron, value),
3353 0, { 0 }, XD_FLAG_NO_KKCC }, 3353 0, { 0 }, XD_FLAG_NO_KKCC },
3354 { XD_END } 3354 { XD_END }
3355 }; 3355 };
3356 3356
3357 DEFINE_NODUMP_LISP_OBJECT ("ephemeron", ephemeron, 3357 DEFINE_NODUMP_LISP_OBJECT ("ephemeron", ephemeron,
3370 will possibly be called on VALUE some time in the future. Moreover, 3370 will possibly be called on VALUE some time in the future. Moreover,
3371 future calls to `ephemeron-ref' will return NIL. 3371 future calls to `ephemeron-ref' will return NIL.
3372 */ 3372 */
3373 (key, value, finalizer)) 3373 (key, value, finalizer))
3374 { 3374 {
3375 return make_ephemeron(key, value, finalizer); 3375 return make_ephemeron (key, value, finalizer);
3376 } 3376 }
3377 3377
3378 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /* 3378 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /*
3379 Return the contents of ephemeron EPHEMERON. 3379 Return the contents of ephemeron EPHEMERON.
3380 If the contents have been GCed, return NIL. 3380 If the contents have been GCed, return NIL.
3381 */ 3381 */
3382 (eph)) 3382 (ephemeron))
3383 { 3383 {
3384 return XEPHEMERON_REF (eph); 3384 return XEPHEMERON_REF (ephemeron);
3385 } 3385 }
3386 3386
3387 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /* 3387 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /*
3388 Return non-nil if OBJECT is an ephemeron. 3388 Return non-nil if OBJECT is an ephemeron.
3389 */ 3389 */