snarf.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* classes: h_files */
  2. /* Macros for snarfing initialization actions from C source. */
  3. #ifndef LIBGUILE_SNARF_H
  4. #define LIBGUILE_SNARF_H
  5. /* Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001, 2003 Free Software Foundation, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this software; see the file COPYING. If not, write to
  19. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301 USA
  21. *
  22. * As a special exception, the Free Software Foundation gives permission
  23. * for additional uses of the text contained in its release of GUILE.
  24. *
  25. * The exception is that, if you link the GUILE library with other files
  26. * to produce an executable, this does not by itself cause the
  27. * resulting executable to be covered by the GNU General Public License.
  28. * Your use of that executable is in no way restricted on account of
  29. * linking the GUILE library code into it.
  30. *
  31. * This exception does not however invalidate any other reasons why
  32. * the executable file might be covered by the GNU General Public License.
  33. *
  34. * This exception applies only to the code released by the
  35. * Free Software Foundation under the name GUILE. If you copy
  36. * code from other Free Software Foundation releases into a copy of
  37. * GUILE, as the General Public License permits, the exception does
  38. * not apply to the code that you add in this way. To avoid misleading
  39. * anyone as to the status of such modified files, you must delete
  40. * this exception notice from them.
  41. *
  42. * If you write modifications of your own for GUILE, it is your choice
  43. * whether to permit this exception to apply to your modifications.
  44. * If you do not wish that, delete this exception notice. */
  45. #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
  46. /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
  47. to like it.
  48. */
  49. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
  50. #else
  51. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
  52. #endif
  53. /* Generic macros to be used in user macro definitions.
  54. *
  55. * For example, in order to define a macro which creates ints and
  56. * initializes them to the result of foo (), do:
  57. *
  58. * #define SCM_FOO(NAME) \
  59. * SCM_SNARF_HERE (int NAME) \
  60. * SCM_SNARF_INIT (NAME = foo ())
  61. *
  62. * The SCM_SNARF_INIT text goes into the corresponding .x file
  63. * up through the first occurrence of SCM_SNARF_DOC_START on that
  64. * line, if any.
  65. */
  66. #ifdef SCM_MAGIC_SNARF_INITS
  67. # define SCM_SNARF_HERE(X)
  68. # define SCM_SNARF_INIT(X) ^^ X
  69. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  70. #else
  71. # ifdef SCM_MAGIC_SNARF_DOCS
  72. # define SCM_SNARF_HERE(X)
  73. # define SCM_SNARF_INIT(X)
  74. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
  75. ^^ { \
  76. cname CNAME ^^ \
  77. fname FNAME ^^ \
  78. type TYPE ^^ \
  79. location __FILE__ __LINE__ ^^ \
  80. arglist ARGLIST ^^ \
  81. argsig REQ OPT VAR ^^ \
  82. DOCSTRING ^^ }
  83. # else
  84. # define SCM_SNARF_HERE(X) X
  85. # define SCM_SNARF_INIT(X)
  86. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  87. # endif
  88. #endif
  89. #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  90. SCM_SNARF_HERE(\
  91. static const char s_ ## FNAME [] = PRIMNAME; \
  92. SCM FNAME ARGLIST\
  93. )\
  94. SCM_SNARF_INIT(\
  95. scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
  96. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
  97. )\
  98. SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  99. #define SCM_PRIMITIVE_GENERIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  100. SCM_SNARF_HERE(\
  101. static const char s_ ## FNAME [] = PRIMNAME; \
  102. static SCM g_ ## FNAME; \
  103. SCM FNAME ARGLIST\
  104. )\
  105. SCM_SNARF_INIT(\
  106. g_ ## FNAME = SCM_PACK (0); \
  107. scm_c_define_gsubr_with_generic (s_ ## FNAME, REQ, OPT, VAR, \
  108. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME, \
  109. &g_ ## FNAME); \
  110. )\
  111. SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  112. #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
  113. SCM_SNARF_HERE(\
  114. static const char s_ ## FNAME [] = PRIMNAME; \
  115. SCM FNAME ARGLIST\
  116. )\
  117. SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
  118. SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
  119. #define SCM_PRIMITIVE_GENERIC_1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
  120. SCM_SNARF_HERE(\
  121. static const char s_ ## FNAME [] = PRIMNAME; \
  122. static SCM g_ ## FNAME; \
  123. SCM FNAME ARGLIST\
  124. )\
  125. SCM_SNARF_INIT(\
  126. g_ ## FNAME = SCM_PACK (0); \
  127. scm_c_define_subr_with_generic (s_ ## FNAME, TYPE, FNAME, &g_ ## FNAME); \
  128. )\
  129. SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
  130. #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  131. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  132. SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
  133. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
  134. #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  135. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  136. SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
  137. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
  138. SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
  139. "implemented by the C function \"" #CFN "\"")
  140. #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
  141. SCM_SNARF_HERE(\
  142. static const char RANAME[]=STR;\
  143. static SCM GF \
  144. )SCM_SNARF_INIT(\
  145. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  146. scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
  147. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  148. )
  149. #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
  150. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  151. SCM_SNARF_INIT(\
  152. scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
  153. )
  154. #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
  155. SCM_SNARF_HERE(\
  156. static const char RANAME[]=STR; \
  157. static SCM GF \
  158. )SCM_SNARF_INIT(\
  159. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  160. scm_c_define_subr_with_generic (RANAME, TYPE, \
  161. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  162. )
  163. #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
  164. SCM_SNARF_HERE(static const char RANAME[]=STR)\
  165. SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
  166. #define SCM_SYMBOL(c_name, scheme_name) \
  167. SCM_SNARF_HERE(static SCM c_name) \
  168. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
  169. #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
  170. SCM_SNARF_HERE(SCM c_name) \
  171. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_str2symbol (scheme_name)))
  172. #define SCM_KEYWORD(c_name, scheme_name) \
  173. SCM_SNARF_HERE(static SCM c_name) \
  174. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
  175. #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
  176. SCM_SNARF_HERE(SCM c_name) \
  177. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
  178. #define SCM_VARIABLE(c_name, scheme_name) \
  179. SCM_SNARF_HERE(static SCM c_name) \
  180. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
  181. #define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
  182. SCM_SNARF_HERE(SCM c_name) \
  183. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
  184. #define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
  185. SCM_SNARF_HERE(static SCM c_name) \
  186. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
  187. #define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
  188. SCM_SNARF_HERE(SCM c_name) \
  189. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
  190. #if (SCM_DEBUG_DEPRECATED == 0)
  191. #define SCM_CONST_LONG(c_name, scheme_name,value) \
  192. SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
  193. #define SCM_VCELL(c_name, scheme_name) \
  194. SCM_SNARF_HERE(static SCM c_name) \
  195. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
  196. #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
  197. SCM_SNARF_HERE(SCM c_name) \
  198. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, SCM_BOOL_F));)
  199. #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
  200. SCM_SNARF_HERE(static SCM c_name) \
  201. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
  202. #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
  203. SCM_SNARF_HERE(SCM c_name) \
  204. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_sysintern (scheme_name, init_val));)
  205. #endif /* (SCM_DEBUG_DEPRECATED == 0) */
  206. #ifdef SCM_MAGIC_SNARF_DOCS
  207. #undef SCM_ASSERT
  208. #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
  209. #endif /* SCM_MAGIC_SNARF_DOCS */
  210. #endif /* LIBGUILE_SNARF_H */
  211. /*
  212. Local Variables:
  213. c-file-style: "gnu"
  214. End:
  215. */