data.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Part of Scheme 48 1.9. See file COPYING for notices and license.
  3. *
  4. * Authors: David Frese
  5. */
  6. #ifndef __S48_GC_DATA_H
  7. #define __S48_GC_DATA_H
  8. #include "scheme48.h"
  9. #include "memory.h" // s48_address
  10. #define S48_UNSIGNED_HIGH_BITS(x, offset, len) ((((unsigned long)(x)) >> offset)\
  11. & ((1L << len) - 1))
  12. /* selecting/mutating fields of a header directly */
  13. #define S48_HEADER_LENGTH_IN_BYTES(h) ((unsigned long)(h) >> 8)
  14. #define S48_HEADER_TYPE(h) S48_UNSIGNED_HIGH_BITS(h, 2, 5)
  15. #define S48_HEADER_LENGTH_IN_CELLS(h) \
  16. S48_BYTES_TO_CELLS(S48_HEADER_LENGTH_IN_BYTES(h))
  17. #define S48_HEADER_LENGTH_IN_A_UNITS(h) \
  18. (S48_BYTES_TO_A_UNITS(S48_HEADER_LENGTH_IN_BYTES(h)))
  19. #define S48_HEADER_IMMUTABLE_P(h) S48_UNSIGNED_HIGH_BITS(h, 7, 1)
  20. #define S48_HEADER_MAKE_IMMUTABLE(h) ((h) |= (1L << 7))
  21. #define S48_HEADER_MAKE_MUTABLE(x) ((h) &= ~(1L << 7))
  22. #define S48_MAKE_HEADER(stobtype, size) ( (size << 8) | (stobtype << 2) | S48_HEADER_TAG )
  23. /* some type predicates */
  24. #define S48_LEAST_B_VECTOR_TYPE S48_STOBTYPE_STRING
  25. #define S48_B_VECTOR_HEADER_P(h) \
  26. (S48_HEADER_TYPE(h) >= S48_LEAST_B_VECTOR_TYPE)
  27. #define S48_D_VECTOR_HEADER_P(h) \
  28. (S48_HEADER_TYPE(h) < S48_LEAST_B_VECTOR_TYPE)
  29. #define S48_CONTINUATION_HEADER_P(h) \
  30. (S48_HEADER_TYPE(h) == S48_STOBTYPE_CONTINUATION)
  31. /* some other stob thing */
  32. #define S48_ADDRESS_TO_STOB_DESCRIPTOR(a) \
  33. ((s48_value)(((unsigned long)a) | S48_STOB_TAG))
  34. #define S48_STOB_OVERHEAD_IN_CELLS 1
  35. #define S48_STOB_OVERHEAD_IN_BYTES \
  36. S48_CELLS_TO_BYTES(S48_STOB_OVERHEAD_IN_CELLS)
  37. #define S48_STOB_OVERHEAD_IN_A_UNITS \
  38. S48_BYTES_TO_A_UNITS(S48_STOB_OVERHEAD_IN_BYTES)
  39. /* repeated from scheme48.h because NO_OLD_FFI is defined sometimes (e.g. socket.c) */
  40. #ifndef S48_ADDRESS_AFTER_HEADER
  41. #define S48_ADDRESS_AFTER_HEADER(x, type) ((type *)((x) - S48_STOB_TAG))
  42. #endif
  43. #ifndef S48_STOB_TAG
  44. #define S48_STOB_TAG 3
  45. #endif
  46. #define S48_ADDRESS_AT_HEADER(stob) \
  47. ((s48_address)(((unsigned long)S48_ADDRESS_AFTER_HEADER(stob, void))\
  48. - S48_STOB_OVERHEAD_IN_A_UNITS))
  49. #endif