snarf.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* classes: h_files */
  2. #ifndef SCM_SNARF_H
  3. #define SCM_SNARF_H
  4. /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /* Macros for snarfing initialization actions from C source. */
  21. #if defined(__cplusplus) || defined(GUILE_CPLUSPLUS_SNARF)
  22. /* This used to be "SCM (*)(...)" but GCC on RedHat 7.1 doesn't seem
  23. to like it.
  24. */
  25. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
  26. #else
  27. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
  28. #endif
  29. /* Generic macros to be used in user macro definitions.
  30. *
  31. * For example, in order to define a macro which creates ints and
  32. * initializes them to the result of foo (), do:
  33. *
  34. * #define SCM_FOO(NAME) \
  35. * SCM_SNARF_HERE (int NAME) \
  36. * SCM_SNARF_INIT (NAME = foo ())
  37. *
  38. * The SCM_SNARF_INIT text goes into the corresponding .x file
  39. * up through the first occurrence of SCM_SNARF_DOC_START on that
  40. * line, if any.
  41. */
  42. #ifdef SCM_MAGIC_SNARF_INITS
  43. # define SCM_SNARF_HERE(X)
  44. # define SCM_SNARF_INIT(X) ^^ X ^:^
  45. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  46. #else
  47. # ifdef SCM_MAGIC_SNARF_DOCS
  48. # define SCM_SNARF_HERE(X)
  49. # define SCM_SNARF_INIT(X)
  50. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING) \
  51. ^^ { \
  52. cname CNAME ^^ \
  53. fname FNAME ^^ \
  54. type TYPE ^^ \
  55. location __FILE__ __LINE__ ^^ \
  56. arglist ARGLIST ^^ \
  57. argsig REQ OPT VAR ^^ \
  58. DOCSTRING ^^ }
  59. # else
  60. # define SCM_SNARF_HERE(X) X
  61. # define SCM_SNARF_INIT(X)
  62. # define SCM_SNARF_DOCS(TYPE, CNAME, FNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  63. # endif
  64. #endif
  65. #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  66. SCM_SNARF_HERE(\
  67. static const char s_ ## FNAME [] = PRIMNAME; \
  68. SCM FNAME ARGLIST\
  69. )\
  70. SCM_SNARF_INIT(\
  71. scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
  72. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
  73. )\
  74. SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  75. #define SCM_PRIMITIVE_GENERIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  76. SCM_SNARF_HERE(\
  77. static const char s_ ## FNAME [] = PRIMNAME; \
  78. static SCM g_ ## FNAME; \
  79. SCM FNAME ARGLIST\
  80. )\
  81. SCM_SNARF_INIT(\
  82. g_ ## FNAME = SCM_PACK (0); \
  83. scm_c_define_gsubr_with_generic (s_ ## FNAME, REQ, OPT, VAR, \
  84. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME, \
  85. &g_ ## FNAME); \
  86. )\
  87. SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  88. #define SCM_DEFINE_PUBLIC(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  89. SCM_SNARF_HERE(\
  90. static const char s_ ## FNAME [] = PRIMNAME; \
  91. SCM FNAME ARGLIST\
  92. )\
  93. SCM_SNARF_INIT(\
  94. scm_c_define_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
  95. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
  96. scm_c_export (s_ ## FNAME, NULL); \
  97. )\
  98. SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
  99. #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
  100. SCM_SNARF_HERE(\
  101. static const char s_ ## FNAME [] = PRIMNAME; \
  102. SCM FNAME ARGLIST\
  103. )\
  104. SCM_SNARF_INIT(scm_c_define_subr (s_ ## FNAME, TYPE, FNAME); ) \
  105. SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
  106. #define SCM_PRIMITIVE_GENERIC_1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
  107. SCM_SNARF_HERE(\
  108. static const char s_ ## FNAME [] = PRIMNAME; \
  109. static SCM g_ ## FNAME; \
  110. SCM FNAME ARGLIST\
  111. )\
  112. SCM_SNARF_INIT(\
  113. g_ ## FNAME = SCM_PACK (0); \
  114. scm_c_define_subr_with_generic (s_ ## FNAME, TYPE, FNAME, &g_ ## FNAME); \
  115. )\
  116. SCM_SNARF_DOCS(1, FNAME, PRIMNAME, ARGLIST, 2, 0, 0, DOCSTRING)
  117. #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  118. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  119. SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
  120. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
  121. #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  122. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  123. SCM_SNARF_INIT(scm_c_define_gsubr (RANAME, REQ, OPT, VAR, \
  124. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
  125. SCM_SNARF_DOCS(register, CFN, STR, (), REQ, OPT, VAR, \
  126. "implemented by the C function \"" #CFN "\"")
  127. #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
  128. SCM_SNARF_HERE(\
  129. static const char RANAME[]=STR;\
  130. static SCM GF \
  131. )SCM_SNARF_INIT(\
  132. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  133. scm_c_define_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
  134. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  135. )
  136. #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
  137. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  138. SCM_SNARF_INIT(\
  139. scm_c_define_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
  140. )
  141. #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
  142. SCM_SNARF_HERE(\
  143. static const char RANAME[]=STR; \
  144. static SCM GF \
  145. )SCM_SNARF_INIT(\
  146. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  147. scm_c_define_subr_with_generic (RANAME, TYPE, \
  148. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  149. )
  150. #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
  151. SCM_SNARF_HERE(static const char RANAME[]=STR)\
  152. SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
  153. #define SCM_SYMBOL(c_name, scheme_name) \
  154. SCM_SNARF_HERE(static SCM c_name) \
  155. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
  156. #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
  157. SCM_SNARF_HERE(SCM c_name) \
  158. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
  159. #define SCM_KEYWORD(c_name, scheme_name) \
  160. SCM_SNARF_HERE(static SCM c_name) \
  161. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
  162. #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
  163. SCM_SNARF_HERE(SCM c_name) \
  164. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
  165. #define SCM_VARIABLE(c_name, scheme_name) \
  166. SCM_SNARF_HERE(static SCM c_name) \
  167. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
  168. #define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
  169. SCM_SNARF_HERE(SCM c_name) \
  170. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
  171. #define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
  172. SCM_SNARF_HERE(static SCM c_name) \
  173. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
  174. #define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
  175. SCM_SNARF_HERE(SCM c_name) \
  176. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
  177. #define SCM_MUTEX(c_name) \
  178. SCM_SNARF_HERE(static scm_t_mutex c_name) \
  179. SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
  180. #define SCM_GLOBAL_MUTEX(c_name) \
  181. SCM_SNARF_HERE(scm_t_mutex c_name) \
  182. SCM_SNARF_INIT(scm_i_plugin_mutex_init (&c_name, &scm_i_plugin_mutex))
  183. #define SCM_REC_MUTEX(c_name) \
  184. SCM_SNARF_HERE(static scm_t_rec_mutex c_name) \
  185. SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
  186. #define SCM_GLOBAL_REC_MUTEX(c_name) \
  187. SCM_SNARF_HERE(scm_t_rec_mutex c_name) \
  188. SCM_SNARF_INIT(scm_i_plugin_rec_mutex_init (&c_name, &scm_i_plugin_rec_mutex))
  189. #define SCM_SMOB(tag, scheme_name, size) \
  190. SCM_SNARF_HERE(static scm_t_bits tag) \
  191. SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
  192. #define SCM_GLOBAL_SMOB(tag, scheme_name, size) \
  193. SCM_SNARF_HERE(scm_t_bits tag) \
  194. SCM_SNARF_INIT((tag)=scm_make_smob_type((scheme_name), (size));)
  195. #define SCM_SMOB_MARK(tag, c_name, arg) \
  196. SCM_SNARF_HERE(static SCM c_name(SCM arg)) \
  197. SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
  198. #define SCM_GLOBAL_SMOB_MARK(tag, c_name, arg) \
  199. SCM_SNARF_HERE(SCM c_name(SCM arg)) \
  200. SCM_SNARF_INIT(scm_set_smob_mark((tag), (c_name));)
  201. #define SCM_SMOB_FREE(tag, c_name, arg) \
  202. SCM_SNARF_HERE(static size_t c_name(SCM arg)) \
  203. SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
  204. #define SCM_GLOBAL_SMOB_FREE(tag, c_name, arg) \
  205. SCM_SNARF_HERE(size_t c_name(SCM arg)) \
  206. SCM_SNARF_INIT(scm_set_smob_free((tag), (c_name));)
  207. #define SCM_SMOB_PRINT(tag, c_name, obj, port, pstate) \
  208. SCM_SNARF_HERE(static int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
  209. SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
  210. #define SCM_GLOBAL_SMOB_PRINT(tag, c_name, obj, port, pstate) \
  211. SCM_SNARF_HERE(int c_name(SCM obj, SCM port, scm_print_state* pstate)) \
  212. SCM_SNARF_INIT(scm_set_smob_print((tag), (c_name));)
  213. #define SCM_SMOB_EQUALP(tag, c_name, obj1, obj2) \
  214. SCM_SNARF_HERE(static SCM c_name(SCM obj1, SCM obj2)) \
  215. SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
  216. #define SCM_GLOBAL_SMOB_EQUALP(tag, c_name, obj1, obj2) \
  217. SCM_SNARF_HERE(SCM c_name(SCM obj1, SCM obj2)) \
  218. SCM_SNARF_INIT(scm_set_smob_equalp((tag), (c_name));)
  219. #define SCM_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
  220. SCM_SNARF_HERE(static SCM c_name arglist) \
  221. SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
  222. #define SCM_GLOBAL_SMOB_APPLY(tag, c_name, req, opt, rest, arglist) \
  223. SCM_SNARF_HERE(SCM c_name arglist) \
  224. SCM_SNARF_INIT(scm_set_smob_apply((tag), (c_name), (req), (opt), (rest));)
  225. #ifdef SCM_MAGIC_SNARF_DOCS
  226. #undef SCM_ASSERT
  227. #define SCM_ASSERT(_cond, _arg, _pos, _subr) ^^ argpos _arg _pos __LINE__ ^^
  228. #endif /* SCM_MAGIC_SNARF_DOCS */
  229. #endif /* SCM_SNARF_H */
  230. /*
  231. Local Variables:
  232. c-file-style: "gnu"
  233. End:
  234. */