2 lily-guile-macros.hh -- declare
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #ifndef LILY_GUILE_MACROS_HH
11 #define LILY_GUILE_MACROS_HH
13 #ifndef SMOB_FREE_RETURN_VAL
14 #define SMOB_FREE_RETURN_VAL(CL) 0
18 #define SCM_PACK(x) ((SCM) x)
22 #define SCM_UNPACK(x) (x)
27 /* Unreliable with gcc-2.x
28 FIXME: should add check for x86 as well? */
34 /* Using this trick we cache the value of scm_str2symbol ("fooo") where
35 "fooo" is a constant string. This is done at the cost of one static
36 variable per ly_symbol2scm() use, and one boolean evaluation for
39 The overall speedup of lily is about 5% on a run of wtk1-fugue2. */
40 #define ly_symbol2scm(x) \
43 /* We store this one locally, since G++ -O2 fucks up else */ \
45 if ( __builtin_constant_p ((x))) \
48 value = cached = scm_gc_protect_object (scm_str2symbol ((x))); \
51 value = scm_str2symbol ((char*) (x)); \
55 inline SCM ly_symbol2scm(char const* x) { return scm_str2symbol ((x)); }
60 TODO: rename me to ly_c_lily_module_eval
62 #define ly_lily_module_constant(x) \
65 /* We store this one locally, since G++ -O2 fucks up else */ \
67 if ( __builtin_constant_p ((x))) \
70 value = cached = scm_gc_protect_object (scm_eval (scm_str2symbol (x), \
71 global_lily_module)); \
74 value = scm_eval (scm_str2symbol (x), global_lily_module); \
81 Adds the NAME as a Scheme function, and a variable to store the SCM
82 version of the function in the static variable NAME_proc
84 #define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \
85 static SCM NAME ARGS; \
86 static SCM NAME ## _proc
89 Make TYPE::FUNC available as a Scheme function.
91 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
92 SCM TYPE :: FUNC ## _proc; \
94 TYPE ## _ ## FUNC ## _init_functions () \
96 TYPE :: FUNC ## _proc = scm_c_define_gsubr (#TYPE "::" #FUNC, \
98 (Scheme_function_unknown)TYPE :: FUNC); \
99 scm_c_export (#TYPE "::" #FUNC, NULL); \
102 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, \
103 TYPE ## _ ## FUNC ## _init_functions);
107 ly_add_function_documentation (SCM proc, char const *fname,
111 #define ADD_SCM_INIT_FUNC(name, func) \
112 class name ## _scm_initter \
115 name ## _scm_initter () \
117 add_scm_init_func (func); \
119 } _ ## name ## _scm_initter; \
122 #define LY_DEFINE_WITHOUT_DECL(INITPREFIX, FNAME, PRIMNAME, REQ, OPT, VAR, \
123 ARGLIST, DOCSTRING) \
124 SCM FNAME ## _proc; \
126 INITPREFIX ## init () \
128 FNAME ## _proc = scm_c_define_gsubr (PRIMNAME, REQ, OPT, VAR, \
129 (Scheme_function_unknown) FNAME); \
130 ly_add_function_documentation (FNAME ## _proc, PRIMNAME, #ARGLIST, \
132 scm_c_export (PRIMNAME, NULL); \
134 ADD_SCM_INIT_FUNC (INITPREFIX ## init_unique_prefix, INITPREFIX ## init); \
139 #define LY_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
141 LY_DEFINE_WITHOUT_DECL (FNAME, FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, \
144 #define LY_DEFINE_MEMBER_FUNCTION(CLASS, FNAME, PRIMNAME, REQ, OPT, VAR, \
145 ARGLIST, DOCSTRING) \
147 LY_DEFINE_WITHOUT_DECL (CLASS ## FNAME, CLASS::FNAME, PRIMNAME, REQ, OPT, \
148 VAR, ARGLIST, DOCSTRING)
150 #define get_property(x) internal_get_property (ly_symbol2scm (x))
151 #define set_property(x, y) internal_set_property (ly_symbol2scm (x), y)
153 #endif /* LILY_GUILE_MACROS_HH */