api-snarf.texi 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004
  4. @c Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node Snarfing Macros
  7. @section Snarfing Macros
  8. @cindex guile-snarf recognized macros
  9. @cindex guile-snarf deprecated macros
  10. The following macros do two different things: when compiled normally,
  11. they expand in one way; when processed during snarfing, they cause the
  12. @code{guile-snarf} program to pick up some initialization code,
  13. @xref{Function Snarfing}.
  14. The descriptions below use the term `normally' to refer to the case
  15. when the code is compiled normally, and `while snarfing' when the code
  16. is processed by @code{guile-snarf}.
  17. @deffn {C Macro} SCM_SNARF_INIT (code)
  18. Normally, @code{SCM_SNARF_INIT} expands to nothing; while snarfing, it
  19. causes @var{code} to be included in the initialization action file,
  20. followed by a semicolon.
  21. This is the fundamental macro for snarfing initialization actions.
  22. The more specialized macros below use it internally.
  23. @end deffn
  24. @deffn {C Macro} SCM_DEFINE (c_name, scheme_name, req, opt, var, arglist, docstring)
  25. Normally, this macro expands into
  26. @smallexample
  27. static const char s_@var{c_name}[] = @var{scheme_name};
  28. SCM
  29. @var{c_name} @var{arglist}
  30. @end smallexample
  31. While snarfing, it causes
  32. @smallexample
  33. scm_c_define_gsubr (s_@var{c_name}, @var{req}, @var{opt}, @var{var},
  34. @var{c_name});
  35. @end smallexample
  36. to be added to the initialization actions. Thus, you can use it to
  37. declare a C function named @var{c_name} that will be made available to
  38. Scheme with the name @var{scheme_name}.
  39. Note that the @var{arglist} argument must have parentheses around it.
  40. @end deffn
  41. @deffn {C Macro} SCM_SYMBOL (c_name, scheme_name)
  42. @deffnx {C Macro} SCM_GLOBAL_SYMBOL (c_name, scheme_name)
  43. Normally, these macros expand into
  44. @smallexample
  45. static SCM @var{c_name}
  46. @end smallexample
  47. or
  48. @smallexample
  49. SCM @var{c_name}
  50. @end smallexample
  51. respectively. While snarfing, they both expand into the
  52. initialization code
  53. @smallexample
  54. @var{c_name} = scm_permanent_object (scm_from_locale_symbol (@var{scheme_name}));
  55. @end smallexample
  56. Thus, you can use them declare a static or global variable of type
  57. @code{SCM} that will be initialized to the symbol named
  58. @var{scheme_name}.
  59. @end deffn
  60. @deffn {C Macro} SCM_KEYWORD (c_name, scheme_name)
  61. @deffnx {C Macro} SCM_GLOBAL_KEYWORD (c_name, scheme_name)
  62. Normally, these macros expand into
  63. @smallexample
  64. static SCM @var{c_name}
  65. @end smallexample
  66. or
  67. @smallexample
  68. SCM @var{c_name}
  69. @end smallexample
  70. respectively. While snarfing, they both expand into the
  71. initialization code
  72. @smallexample
  73. @var{c_name} = scm_permanent_object (scm_c_make_keyword (@var{scheme_name}));
  74. @end smallexample
  75. Thus, you can use them declare a static or global variable of type
  76. @code{SCM} that will be initialized to the keyword named
  77. @var{scheme_name}.
  78. @end deffn
  79. @deffn {C Macro} SCM_VARIABLE (c_name, scheme_name)
  80. @deffnx {C Macro} SCM_GLOBAL_VARIABLE (c_name, scheme_name)
  81. These macros are equivalent to @code{SCM_VARIABLE_INIT} and
  82. @code{SCM_GLOBAL_VARIABLE_INIT}, respectively, with a @var{value} of
  83. @code{SCM_BOOL_F}.
  84. @end deffn
  85. @deffn {C Macro} SCM_VARIABLE_INIT (c_name, scheme_name, value)
  86. @deffnx {C Macro} SCM_GLOBAL_VARIABLE_INIT (c_name, scheme_name, value)
  87. Normally, these macros expand into
  88. @smallexample
  89. static SCM @var{c_name}
  90. @end smallexample
  91. or
  92. @smallexample
  93. SCM @var{c_name}
  94. @end smallexample
  95. respectively. While snarfing, they both expand into the
  96. initialization code
  97. @smallexample
  98. @var{c_name} = scm_permanent_object (scm_c_define (@var{scheme_name}, @var{value}));
  99. @end smallexample
  100. Thus, you can use them declare a static or global C variable of type
  101. @code{SCM} that will be initialized to the object representing the
  102. Scheme variable named @var{scheme_name} in the current module. The
  103. variable will be defined when it doesn't already exist. It is always
  104. set to @var{value}.
  105. @end deffn