snarf.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef SCM_SNARF_H
  2. #define SCM_SNARF_H
  3. /* Copyright 1995-2004,2006,2009-2011,2013-2014,2017-2019
  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/scm.h>
  18. /* Macros for snarfing initialization actions from C source. */
  19. #ifdef SCM_ALIGNED
  20. /* We support static allocation of some `SCM' objects. */
  21. # define SCM_SUPPORT_STATIC_ALLOCATION
  22. #endif
  23. /* C preprocessor token concatenation. */
  24. #define scm_i_paste(x, y) x ## y
  25. #define scm_i_paste3(a, b, c) a ## b ## c
  26. /* Generic macros to be used in user macro definitions.
  27. *
  28. * For example, in order to define a macro which creates ints and
  29. * initializes them to the result of foo (), do:
  30. *
  31. * #define SCM_FOO(NAME) \
  32. * SCM_SNARF_HERE (int NAME) \
  33. * SCM_SNARF_INIT (NAME = foo ())
  34. *
  35. * The SCM_SNARF_INIT text goes into the corresponding .x file
  36. * up through the first occurrence of SCM_SNARF_DOC_START on that
  37. * line, if any.
  38. *
  39. * Some debugging options can cause the preprocessor to echo #define
  40. * directives to its output. Keeping the snarfing markers on separate
  41. * lines prevents guile-snarf from inadvertently snarfing the definition
  42. * of SCM_SNARF_INIT if those options are in effect.
  43. */
  44. #ifdef SCM_MAGIC_SNARF_INITS
  45. # define SCM_SNARF_HERE(X)
  46. # define SCM_SNARF_INIT_PREFIX ^^
  47. # define SCM_SNARF_INIT(X) SCM_SNARF_INIT_PREFIX X ^:^
  48. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  49. #else
  50. # ifdef SCM_MAGIC_SNARF_DOCS
  51. # define SCM_SNARF_HERE(X)
  52. # define SCM_SNARF_INIT(X)
  53. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
  54. ^^ { \
  55. cname CNAME ^^ \
  56. fname FNAME ^^ \
  57. type TYPE ^^ \
  58. location __FILE__ __LINE__ ^^ \
  59. arglist ARGLIST ^^ \
  60. argsig REQ OPT VAR ^^ \
  61. DOCSTRING ^^ }
  62. # else
  63. # define SCM_SNARF_HERE(X) X
  64. # define SCM_SNARF_INIT(X)
  65. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  66. # endif
  67. #endif
  68. /* Low-level snarfing for static memory allocation. */
  69. #ifdef SCM_SUPPORT_STATIC_ALLOCATION
  70. #define SCM_IMMUTABLE_CELL(c_name, car, cdr) \
  71. static SCM_ALIGNED (8) const SCM c_name ## _raw [2] = \
  72. { SCM_PACK (car), SCM_PACK (cdr) }; \
  73. static SCM_UNUSED const SCM c_name = SCM_PACK (& c_name ## _raw)
  74. #define SCM_IMMUTABLE_DOUBLE_CELL(c_name, car, cbr, ccr, cdr) \
  75. static SCM_ALIGNED (8) const SCM c_name ## _raw [4] = \
  76. { SCM_PACK (car), SCM_PACK (cbr), SCM_PACK (ccr), SCM_PACK (cdr) }; \
  77. static SCM_UNUSED const SCM c_name = SCM_PACK (& c_name ## _raw)
  78. #endif /* SCM_SUPPORT_STATIC_ALLOCATION */
  79. /* Documentation. */
  80. #ifdef SCM_MAGIC_SNARF_DOCS
  81. #undef SCM_ASSERT
  82. #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
  83. #endif /* SCM_MAGIC_SNARF_DOCS */
  84. #endif /* SCM_SNARF_H */