snarf.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, 2002 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., 59 Temple Place, Suite 330,
  20. * Boston, MA 02111-1307 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. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)(...)
  47. #else
  48. #define SCM_FUNC_CAST_ARBITRARY_ARGS SCM (*)()
  49. #endif
  50. /* Generic macros to be used in user macro definitions.
  51. *
  52. * For example, in order to define a macro which creates ints and
  53. * initializes them to the result of foo (), do:
  54. *
  55. * #define SCM_FOO(NAME) \
  56. * SCM_SNARF_HERE (int NAME) \
  57. * SCM_SNARF_INIT (NAME = foo ())
  58. *
  59. * The SCM_SNARF_INIT text goes into the corresponding .x file
  60. * up through the first occurrence of SCM__D on that line, if any.
  61. */
  62. #ifndef SCM_MAGIC_SNARFER
  63. # define SCM_SNARF_HERE(X) X
  64. # define SCM_SNARF_INIT(X)
  65. # define SCM_SNARF_DOCS(X)
  66. #else
  67. # define SCM_SNARF_HERE(X)
  68. # define SCM_SNARF_INIT(X) SCM__I X
  69. # define SCM_SNARF_DOCS(X) X
  70. #endif
  71. #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
  72. SCM_SNARF_HERE(\
  73. static const char s_ ## FNAME [] = PRIMNAME; \
  74. SCM FNAME ARGLIST\
  75. )\
  76. SCM_SNARF_INIT(\
  77. scm_make_gsubr (s_ ## FNAME, REQ, OPT, VAR, \
  78. (SCM_FUNC_CAST_ARBITRARY_ARGS) FNAME); \
  79. )\
  80. SCM_SNARF_DOCS(\
  81. SCM__DP PRIMNAME #ARGLIST | REQ | OPT | VAR | __FILE__:__LINE__ | SCM__S DOCSTRING SCM__E \
  82. )
  83. #define SCM_DEFINE1(FNAME, PRIMNAME, TYPE, ARGLIST, DOCSTRING) \
  84. SCM_SNARF_HERE(\
  85. static const char s_ ## FNAME [] = PRIMNAME; \
  86. SCM FNAME ARGLIST\
  87. )\
  88. SCM_SNARF_INIT(scm_make_subr (s_ ## FNAME, TYPE, FNAME); ) \
  89. SCM_SNARF_DOCS(\
  90. SCM__D1 PRIMNAME #ARGLIST | 2 | 0 | 0 | __FILE__:__LINE__ | SCM__S DOCSTRING SCM__E \
  91. )
  92. #define SCM_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  93. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  94. SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
  95. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN))
  96. #define SCM_REGISTER_PROC(RANAME, STR, REQ, OPT, VAR, CFN) \
  97. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  98. SCM_SNARF_INIT(scm_make_gsubr (RANAME, REQ, OPT, VAR, \
  99. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN);) \
  100. SCM_SNARF_DOCS(\
  101. SCM__DR STR | REQ | OPT | VAR | __FILE__:__LINE__ | SCM__S CFN SCM__E \
  102. )
  103. #define SCM_GPROC(RANAME, STR, REQ, OPT, VAR, CFN, GF) \
  104. SCM_SNARF_HERE(\
  105. static const char RANAME[]=STR;\
  106. static SCM GF \
  107. )SCM_SNARF_INIT(\
  108. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  109. scm_make_gsubr_with_generic (RANAME, REQ, OPT, VAR, \
  110. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  111. )
  112. #define SCM_PROC1(RANAME, STR, TYPE, CFN) \
  113. SCM_SNARF_HERE(static const char RANAME[]=STR) \
  114. SCM_SNARF_INIT(\
  115. scm_make_subr (RANAME, TYPE, (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN) \
  116. )
  117. #define SCM_GPROC1(RANAME, STR, TYPE, CFN, GF) \
  118. SCM_SNARF_HERE(\
  119. static const char RANAME[]=STR; \
  120. static SCM GF \
  121. )SCM_SNARF_INIT(\
  122. GF = SCM_PACK (0); /* Dirk:FIXME:: Can we safely use #f instead of 0? */ \
  123. scm_make_subr_with_generic (RANAME, TYPE, \
  124. (SCM_FUNC_CAST_ARBITRARY_ARGS) CFN, &GF) \
  125. )
  126. #define SCM_SYNTAX(RANAME, STR, TYPE, CFN) \
  127. SCM_SNARF_HERE(static const char RANAME[]=STR)\
  128. SCM_SNARF_INIT(scm_make_synt (RANAME, TYPE, CFN))
  129. #define SCM_SYMBOL(c_name, scheme_name) \
  130. SCM_SNARF_HERE(static SCM c_name) \
  131. SCM_SNARF_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
  132. #define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
  133. SCM_SNARF_HERE(SCM c_name) \
  134. SCM_SNARF_INIT(c_name = scm_permanent_object (SCM_CAR (scm_intern0 (scheme_name))))
  135. #define SCM_KEYWORD(c_name, scheme_name) \
  136. SCM_SNARF_HERE(static SCM c_name) \
  137. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
  138. #define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
  139. SCM_SNARF_HERE(SCM c_name) \
  140. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_make_keyword (scheme_name)))
  141. #define SCM_VCELL(c_name, scheme_name) \
  142. SCM_SNARF_HERE(static SCM c_name) \
  143. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
  144. #define SCM_GLOBAL_VCELL(c_name, scheme_name) \
  145. SCM_SNARF_HERE(SCM c_name) \
  146. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, SCM_BOOL_F))
  147. #define SCM_VCELL_INIT(c_name, scheme_name, init_val) \
  148. SCM_SNARF_HERE(static SCM c_name) \
  149. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
  150. #define SCM_GLOBAL_VCELL_INIT(c_name, scheme_name, init_val) \
  151. SCM_SNARF_HERE(SCM c_name) \
  152. SCM_SNARF_INIT(c_name = scm_permanent_object (scm_intern0 (scheme_name)); SCM_SETCDR (c_name, init_val))
  153. #define SCM_CONST_LONG(c_name, scheme_name,value) \
  154. SCM_VCELL_INIT(c_name, scheme_name, scm_long2num(value))
  155. #ifdef SCM_MAGIC_SNARFER
  156. #undef SCM_ASSERT
  157. #define SCM_ASSERT(_cond, _arg, _pos, _subr) *&*&*&*SCM_ARG_BETTER_BE_IN_POSITION(_arg,_pos,__LINE__)
  158. #endif /* SCM_MAGIC_SNARFER */
  159. #endif /* LIBGUILE_SNARF_H */
  160. /*
  161. Local Variables:
  162. c-file-style: "gnu"
  163. End:
  164. */