weak-list.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef SCM_WEAK_LIST_H
  2. #define SCM_WEAK_LIST_H
  3. /* Copyright 2016,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/pairs.h"
  18. #include "libguile/weak-vector.h"
  19. static inline SCM
  20. scm_i_weak_cons (SCM car, SCM cdr)
  21. {
  22. return scm_cons (scm_c_make_weak_vector (1, car), cdr);
  23. }
  24. static inline SCM
  25. scm_i_weak_car (SCM pair)
  26. {
  27. return scm_c_weak_vector_ref (scm_car (pair), 0);
  28. }
  29. static inline void
  30. scm_i_visit_weak_list (SCM *list_loc, void (*visit) (SCM))
  31. {
  32. SCM in = *list_loc, out = SCM_EOL;
  33. while (scm_is_pair (in))
  34. {
  35. SCM car = scm_i_weak_car (in);
  36. SCM cdr = scm_cdr (in);
  37. if (!scm_is_eq (car, SCM_BOOL_F))
  38. {
  39. scm_set_cdr_x (in, out);
  40. out = in;
  41. visit (car);
  42. }
  43. in = cdr;
  44. }
  45. *list_loc = out;
  46. }
  47. #endif /* SCM_WEAK_LIST_H */