2 lily-guile.hh encapsulate guile
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
12 #define SCM_VOIDP_TEST
17 TODO: the GH interface is deprecated as of GUILE 1.6
19 Remove all gh_XXX functions.
25 /* Guile 1.3.4 compatibility */
26 #if GUILE_MINOR_VERSION < 4
30 #define SCM_CELL_TYPE(X) SCM_CAR (X)
33 #ifndef SCM_CELL_WORD_1
34 #define SCM_CELL_WORD_1(X) SCM_CDR (X)
37 #define scm_bits_t SCM
39 #define fix_guile_1_3_4_scm_puts(scm_data, port) scm_puts ((char*)scm_data, port)
40 #define scm_puts(scm_data, port) fix_guile_1_3_4_scm_puts (scm_data, port)
43 /* Guile 1.4.x compatibility */
44 #if GUILE_MINOR_VERSION < 5
46 #define scm_t_bits scm_bits_t
48 #define fix_guile_1_4_gh_scm2newstr(str, lenp) gh_scm2newstr (str, (int*)lenp)
49 #define gh_scm2newstr(str, lenp) fix_guile_1_4_gh_scm2newstr (str, lenp)
51 #define fix_guile_1_4_scm_primitive_eval(form) scm_eval_3 (form, 1, SCM_EOL)
52 #define scm_primitive_eval(form) fix_guile_1_4_scm_primitive_eval (form)
54 #define scm_c_define_gsubr scm_make_gsubr
55 #define scm_c_eval_string(str) gh_eval_str ((char*)str)
56 #define scm_c_memq scm_sloppy_memq
57 #define scm_gc_protect_object scm_protect_object
58 #define scm_gc_unprotect_object scm_unprotect_object
59 #define scm_list_n scm_listify
60 #define SCM_STRING_CHARS SCM_CHARS
61 #define SCM_STRING_LENGTH SCM_LENGTH
62 #define SCM_SYMBOL_CHARS SCM_CHARS
63 #define SCM_SYMBOL_LENGTH SCM_LENGTH
68 #include "direction.hh"
69 #include "flower-proto.hh"
72 #define SCM_PACK(x) ((SCM) x)
76 #define SCM_UNPACK(x) ( x)
80 conversion functions follow the GUILE naming convention, i.e.
85 SCM ly_last (SCM list);
86 SCM ly_str02scm (char const*c);
87 SCM ly_write2scm (SCM s);
88 SCM ly_deep_copy (SCM);
89 SCM ly_truncate_list (int k, SCM l );
94 SCM my_gh_symbol2scm (const char* x);
96 // #warning: CACHE_SYMBOLS
99 Using this trick we cache the value of gh_symbol2scm ("fooo") where
100 "fooo" is a constant string. This is done at the cost of one static
101 variable per ly_symbol2scm() use, and one boolean evaluation for
104 The overall speedup of lily is about 5% on a run of wtk1-fugue2
107 #define ly_symbol2scm(x) ({ static SCM cached; \
108 SCM value = cached; /* We store this one locally, since G++ -O2 fucks up else */ \
109 if ( __builtin_constant_p ((x)))\
111 value = cached = scm_gc_protect_object (my_gh_symbol2scm((char*) (x)));\
113 value = gh_symbol2scm ((char*) (x)); \
116 inline SCM ly_symbol2scm(char const* x) { return gh_symbol2scm((char*)x); }
121 String ly_scm2string (SCM s);
122 String ly_symbol2string (SCM);
123 SCM ly_offset2scm (Offset);
124 Offset ly_scm2offset (SCM);
125 SCM ly_assoc_chain (SCM key, SCM achain);
126 Interval ly_scm2interval (SCM);
127 SCM ly_interval2scm (Interval);
129 SCM ly_parse_scm (char const* s, int* n);
130 SCM ly_quote_scm (SCM s);
132 bool type_check_assignment (SCM val, SCM sym, SCM type_symbol) ;
133 SCM ly_number2string (SCM s);
135 SCM parse_symbol_list (char const *);
137 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
138 inline SCM ly_car (SCM x) { return SCM_CAR (x); }
139 inline SCM ly_caar (SCM x) { return SCM_CAAR (x); }
140 inline SCM ly_cdar (SCM x) { return SCM_CDAR (x); }
141 inline SCM ly_cadr (SCM x) { return SCM_CADR (x); }
142 inline SCM ly_cddr (SCM x) { return SCM_CDDR (x); }
143 inline SCM ly_caddr (SCM x) { return SCM_CADDR (x); }
144 inline SCM ly_cdadr (SCM x) { return SCM_CDADR (x); }
145 inline SCM ly_caadr (SCM x) { return SCM_CAADR (x); }
146 inline bool ly_pair_p (SCM x) { return SCM_NFALSEP (scm_pair_p (x)); }
147 inline bool ly_symbol_p (SCM x) { return SCM_SYMBOLP (x); }
148 inline bool ly_number_p (SCM x) { return SCM_NUMBERP (x); }
149 inline bool ly_procedure_p (SCM x) { return SCM_NFALSEP (scm_procedure_p(x)); }
152 display and print newline.
155 void ly_display_scm (SCM s);
160 void read_lily_scm_file (String);
161 void init_lily_guile ();
163 bool isdir_b (SCM s);
164 bool isaxis_b (SCM s);
165 bool ly_number_pair_p (SCM);
166 bool ly_axis_p (SCM);
169 these conversion functions also do a typecheck on the argument, and
170 return a default value if S has the wrong type.
173 Direction to_dir (SCM s);
174 bool to_boolean (SCM s);
176 void init_ly_protection ();
177 unsigned int ly_scm_hash (SCM s);
179 SCM index_cell (SCM cellp, Direction d);
180 SCM index_set_cell (SCM cellp, Direction d, SCM val);
186 void add_scm_init_func (void (*) ());
189 typedef SCM (*Scheme_function_unknown) ();
191 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
192 typedef SCM (*Scheme_function_0) ();
193 typedef SCM (*Scheme_function_1) (SCM);
194 typedef SCM (*Scheme_function_2) (SCM,SCM);
196 typedef SCM (*Scheme_function_0) (...);
197 typedef SCM (*Scheme_function_1) (...);
198 typedef SCM (*Scheme_function_2) (...);
201 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
202 static SCM NAME ARGS; \
203 static SCM NAME ## _proc
205 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
206 SCM TYPE :: FUNC ## _proc;\
208 TYPE ## _ ## FUNC ## _init_functions () \
210 TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT ## _0 (#TYPE "::" #FUNC, \
211 ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC)); \
214 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions); \
217 #define ADD_SCM_INIT_FUNC(name, func)\
218 class name ## _scm_initter { \
220 name ## _scm_initter () \
222 add_scm_init_func (func); \
224 } _ ## name ## _scm_initter; \
227 #endif // LILY_GUILE_HH