2 lily-guile.hh encapsulate guile
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
14 TODO: the GH interface is deprecated as of GUILE 1.6
16 Remove all gh_XXX functions.
21 /* GUILE only includes version in headers (libguile/version.h) as of
22 1.5.x. For some strange reason, they call it SCM.*VERSION.
24 Not including config.h here, saves a lot of unnecessary
28 #ifndef GUILE_MAJOR_VERSION
29 #ifdef SCM_MAJOR_VERSION
30 #define GUILE_MAJOR_VERSION SCM_MAJOR_VERSION
31 #define GUILE_MINOR_VERSION SCM_MINOR_VERSION
32 #define GUILE_PATCH_LEVEL SCM_MICRO_VERSION
38 #include "drul-array.hh"
40 /* Guile 1.4.x compatibility */
41 #if GUILE_MINOR_VERSION < 5
43 #define scm_t_bits scm_bits_t
45 #define fix_guile_1_4_gh_scm2newstr(str, lenp) gh_scm2newstr (str, (int*)lenp)
46 #define gh_scm2newstr(str, lenp) fix_guile_1_4_gh_scm2newstr (str, lenp)
48 #define fix_guile_1_4_scm_primitive_eval(form) scm_eval_3 (form, 1, SCM_EOL)
49 #define scm_primitive_eval(form) fix_guile_1_4_scm_primitive_eval (form)
51 #define scm_current_module() (SCM)0
52 #define scm_set_current_module(x) (void)x
53 #define scm_c_resolve_module(x) (SCM)0
55 inline SCM scm_c_make_vector (int k, SCM val) {
56 return scm_make_vector (SCM_MAKINUM (k), val);
58 #define scm_c_define_gsubr scm_make_gsubr
59 #define scm_c_eval_string(str) gh_eval_str ((char*)str)
61 #define scm_gc_protect_object scm_protect_object
62 #define scm_gc_unprotect_object scm_unprotect_object
63 #define scm_list_n scm_listify
64 #define SCM_STRING_CHARS SCM_CHARS
65 #define SCM_STRING_LENGTH SCM_LENGTH
66 #define SCM_SYMBOL_CHARS SCM_CHARS
67 #define SCM_SYMBOL_LENGTH SCM_LENGTH
68 #define SCM_VECTOR_LENGTH SCM_LENGTH
70 #define SMOB_FREE_RETURN_VAL(CL) sizeof(CL)
71 #define scm_done_free(x)
74 #ifndef SMOB_FREE_RETURN_VAL
75 #define SMOB_FREE_RETURN_VAL(CL) 0
79 #if GUILE_MINOR_VERSION < 7
80 #define scm_gc_unregister_collectable_memory(a,b,c) scm_done_free(b)
81 #define scm_gc_register_collectable_memory(a,b,c) scm_done_malloc(b)
84 #include "direction.hh"
85 #include "flower-proto.hh"
88 #define SCM_PACK(x) ((SCM) x)
92 #define SCM_UNPACK(x) ( x)
96 conversion functions follow the GUILE naming convention, i.e.
101 SCM ly_last (SCM list);
102 SCM ly_write2scm (SCM s);
103 SCM ly_deep_copy (SCM);
104 SCM ly_truncate_list (int k, SCM l );
109 todo: should add check for x86 as well
111 #define CACHE_SYMBOLS
119 Using this trick we cache the value of gh_symbol2scm ("fooo") where
120 "fooo" is a constant string. This is done at the cost of one static
121 variable per ly_symbol2scm() use, and one boolean evaluation for
124 The overall speedup of lily is about 5% on a run of wtk1-fugue2
127 #define ly_symbol2scm(x) ({ static SCM cached; \
128 SCM value = cached; /* We store this one locally, since G++ -O2 fucks up else */ \
129 if ( __builtin_constant_p ((x)))\
131 value = cached = scm_gc_protect_object (my_gh_symbol2scm((x)));\
133 value = gh_symbol2scm ((char*) (x)); \
136 inline SCM ly_symbol2scm(char const* x) { return gh_symbol2scm((x)); }
141 String ly_scm2string (SCM s);
142 String ly_symbol2string (SCM);
143 SCM ly_offset2scm (Offset);
144 Offset ly_scm2offset (SCM);
145 SCM ly_assoc_chain (SCM key, SCM achain);
146 SCM ly_assoc_cdr (SCM key, SCM alist);
147 Interval ly_scm2interval (SCM);
148 Slice int_list_to_slice (SCM l);
149 SCM ly_interval2scm (Drul_array<Real>);
153 SCM ly_quote_scm (SCM s);
154 bool type_check_assignment (SCM val, SCM sym, SCM type_symbol) ;
155 String print_scm_val (SCM val);
156 SCM ly_number2string (SCM s);
158 SCM parse_symbol_list (char const *);
159 SCM robust_list_ref(int i, SCM l);
162 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
163 inline SCM ly_car (SCM x) { return SCM_CAR (x); }
164 inline SCM ly_caar (SCM x) { return SCM_CAAR (x); }
165 inline SCM ly_cdar (SCM x) { return SCM_CDAR (x); }
166 inline SCM ly_cadr (SCM x) { return SCM_CADR (x); }
167 inline SCM ly_cddr (SCM x) { return SCM_CDDR (x); }
168 inline SCM ly_caddr (SCM x) { return SCM_CADDR (x); }
169 inline SCM ly_cdadr (SCM x) { return SCM_CDADR (x); }
170 inline SCM ly_caadr (SCM x) { return SCM_CAADR (x); }
171 /* inserts at front, removing dublicates */
172 inline SCM ly_assoc_front_x(SCM alist, SCM key, SCM val)
174 return scm_acons(key, val, scm_assoc_remove_x (alist, key));
177 #define gh_pair_p ly_pair_p
178 bool ly_pair_p (SCM x);
180 inline bool ly_pair_p (SCM x) { return SCM_NFALSEP (scm_pair_p (x)); }
182 inline bool ly_symbol_p (SCM x) { return SCM_SYMBOLP (x); }
183 inline bool ly_number_p (SCM x) { return SCM_NUMBERP (x); }
184 inline bool ly_procedure_p (SCM x) { return SCM_NFALSEP (scm_procedure_p (x)); }
187 display and print newline.
190 void ly_display_scm (SCM s);
195 void read_lily_scm_file (String);
196 void ly_init_guile ();
198 bool ly_dir_p (SCM s);
199 bool ly_number_pair_p (SCM);
200 bool ly_axis_p (SCM);
203 these conversion functions also do a typecheck on the argument, and
204 return a default value if S has the wrong type.
207 Direction to_dir (SCM s);
208 bool to_boolean (SCM s);
210 void init_ly_protection ();
211 unsigned int ly_scm_hash (SCM s);
213 SCM index_get_cell (SCM cell, Direction d);
214 SCM index_set_cell (SCM cell, Direction d, SCM val);
218 SCM ly_snoc (SCM s, SCM list);
219 SCM ly_split_list (SCM s, SCM list);
220 SCM ly_unique (SCM list);
224 void add_scm_init_func (void (*) ());
227 typedef SCM (*Scheme_function_unknown) ();
229 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
230 typedef SCM (*Scheme_function_0) ();
231 typedef SCM (*Scheme_function_1) (SCM);
232 typedef SCM (*Scheme_function_2) (SCM,SCM);
233 typedef SCM (*Scheme_function_3) (SCM,SCM, SCM);
235 typedef SCM (*Scheme_function_0) (...);
236 typedef SCM (*Scheme_function_1) (...);
237 typedef SCM (*Scheme_function_2) (...);
238 typedef SCM (*Scheme_function_3) (...);
241 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
242 static SCM NAME ARGS; \
243 static SCM NAME ## _proc
245 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
246 SCM TYPE :: FUNC ## _proc;\
248 TYPE ## _ ## FUNC ## _init_functions () \
250 TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT ## _0 (#TYPE "::" #FUNC, \
251 ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC)); \
254 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions); \
257 void ly_add_function_documentation (char const * fname,
258 char const * varlist,
261 #define ADD_SCM_INIT_FUNC(name, func)\
262 class name ## _scm_initter { \
264 name ## _scm_initter () \
266 add_scm_init_func (func); \
268 } _ ## name ## _scm_initter; \
271 #define LY_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
272 SCM FNAME ARGLIST ; \
278 = scm_c_define_gsubr (PRIMNAME,REQ, OPT, VAR, (Scheme_function_unknown) FNAME);\
279 ly_add_function_documentation (PRIMNAME, #ARGLIST, DOCSTRING);\
281 ADD_SCM_INIT_FUNC (FNAME ## init_unique_prefix, FNAME ## init);\
289 #endif // LILY_GUILE_HH