2 lily-guile-macros.hh -- declare
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #ifndef LILY_GUILE_MACROS_HH
10 #define LILY_GUILE_MACROS_HH
12 #ifndef SMOB_FREE_RETURN_VAL
13 #define SMOB_FREE_RETURN_VAL(CL) 0
17 #define SCM_PACK(x) ((SCM) x)
21 #define SCM_UNPACK(x) (x)
24 /* Unreliable with gcc-2.x
25 FIXME: should add check for x86 as well? */
33 /* this lets us "overload" macros such as get_property to take
34 symbols as well as strings */
36 scm_or_str2symbol (char const *c) { return scm_str2symbol (c); }
39 scm_or_str2symbol (SCM s) {
40 assert (scm_is_symbol (s));
44 /* Using this trick we cache the value of scm_str2symbol ("fooo") where
45 "fooo" is a constant string. This is done at the cost of one static
46 variable per ly_symbol2scm() use, and one boolean evaluation for
49 #define ly_symbol2scm(x) \
52 /* We store this one locally, since G++ -O2 fucks up else */ \
54 if (__builtin_constant_p ((x))) \
57 value = cached = scm_gc_protect_object (scm_or_str2symbol (x)); \
60 value = scm_or_str2symbol (x); \
64 inline SCM ly_symbol2scm (char const *x) { return scm_str2symbol ((x)); }
68 TODO: rename me to ly_c_lily_module_eval
70 we don't have to protect the result; it's already part of the
71 exports list of the module.
74 #define ly_lily_module_constant(x) \
77 /* We store this one locally, since G++ -O2 fucks up else */ \
79 if (__builtin_constant_p ((x))) \
82 value = cached = scm_eval (scm_str2symbol (x), \
83 global_lily_module); \
86 value = scm_eval (scm_str2symbol (x), global_lily_module); \
91 Adds the NAME as a Scheme function, and a variable to store the SCM
92 version of the function in the static variable NAME_proc
94 #define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \
95 static SCM NAME ARGS; \
96 static SCM NAME ## _proc
99 Make TYPE::FUNC available as a Scheme function.
101 string mangle_cxx_identifier (string);
102 #define MAKE_SCHEME_CALLBACK_WITH_OPTARGS(TYPE, FUNC, ARGCOUNT, OPTIONAL_COUNT) \
103 SCM TYPE ::FUNC ## _proc; \
105 TYPE ## _ ## FUNC ## _init_functions () \
107 string id = mangle_cxx_identifier (string (#TYPE) + "::" + string (#FUNC)); \
108 TYPE ::FUNC ## _proc = scm_c_define_gsubr (id.c_str(), \
109 (ARGCOUNT-OPTIONAL_COUNT), OPTIONAL_COUNT, 0, \
110 (Scheme_function_unknown) TYPE::FUNC); \
111 scm_c_export (id.c_str (), NULL); \
114 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, \
115 TYPE ## _ ## FUNC ## _init_functions);
117 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
118 MAKE_SCHEME_CALLBACK_WITH_OPTARGS(TYPE,FUNC,ARGCOUNT,0);
121 ly_add_function_documentation (SCM proc, char const *fname,
125 #define ADD_SCM_INIT_FUNC(name, func) \
126 class name ## _scm_initter \
129 name ## _scm_initter () \
131 add_scm_init_func (func); \
134 _ ## name ## _scm_initter;
138 #define LY_DEFINE_WITHOUT_DECL(INITPREFIX, FNAME, PRIMNAME, REQ, OPT, VAR, \
139 ARGLIST, DOCSTRING) \
140 SCM FNAME ## _proc; \
142 INITPREFIX ## init () \
144 FNAME ## _proc = scm_c_define_gsubr (PRIMNAME, REQ, OPT, VAR, \
145 (Scheme_function_unknown) FNAME); \
146 ly_add_function_documentation (FNAME ## _proc, PRIMNAME, #ARGLIST, \
148 scm_c_export (PRIMNAME, NULL); \
150 ADD_SCM_INIT_FUNC (INITPREFIX ## init_unique_prefix, INITPREFIX ## init); \
154 #define LY_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
156 LY_DEFINE_WITHOUT_DECL (FNAME, FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, \
159 #define LY_DEFINE_MEMBER_FUNCTION(CLASS, FNAME, PRIMNAME, REQ, OPT, VAR, \
160 ARGLIST, DOCSTRING) \
162 LY_DEFINE_WITHOUT_DECL (CLASS ## FNAME, CLASS::FNAME, PRIMNAME, REQ, OPT, \
163 VAR, ARGLIST, DOCSTRING)
165 #define get_property(x) internal_get_property (ly_symbol2scm (x))
166 #define get_property_data(x) internal_get_property_data (ly_symbol2scm (x))
167 #define get_object(x) internal_get_object (ly_symbol2scm (x))
168 #define set_object(x, y) internal_set_object (ly_symbol2scm (x), y)
169 #define del_property(x) internal_del_property (ly_symbol2scm (x))
172 #define set_property(x, y) internal_set_property (ly_symbol2scm (x), y, __FILE__, __LINE__, __FUNCTION__)
174 #define set_property(x, y) internal_set_property (ly_symbol2scm (x), y)
177 #endif /* LILY_GUILE_MACROS_HH */