]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
release: 1.5.18
[lilypond.git] / lily / include / lily-guile.hh
1 /*
2   lily-guile.hh encapsulate guile
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #ifndef LILY_GUILE_HH
10 #define LILY_GUILE_HH
11
12 #include <libguile.h>
13
14 /*
15   TODO: the  GH interface is deprecated as of GUILE 1.6
16
17   Remove all gh_XXX functions.
18  */
19 #include <guile/gh.h>
20
21 #include "config.h"
22
23 /* Guile 1.3.4 compatibility */
24 #if GUILE_MINOR_VERSION < 4
25
26
27 #ifndef SCM_CELL_TYPE
28 #define SCM_CELL_TYPE(X) SCM_CAR (X)
29 #endif
30
31 #ifndef SCM_CELL_WORD_1
32 #define SCM_CELL_WORD_1(X) SCM_CDR (X)
33 #endif
34
35 #define scm_bits_t SCM
36
37 #define fix_guile_1_3_4_scm_puts(scm_data, port) scm_puts ((char*)scm_data, port)
38 #define scm_puts(scm_data, port) fix_guile_1_3_4_scm_puts (scm_data, port)
39 #endif
40
41 /* Guile 1.4.x compatibility */
42 #if GUILE_MINOR_VERSION < 5
43
44 #define scm_t_bits scm_bits_t
45
46 #define fix_guile_1_4_gh_scm2newstr(str, lenp) gh_scm2newstr (str, (int*)lenp)
47 #define gh_scm2newstr(str, lenp) fix_guile_1_4_gh_scm2newstr (str, lenp)
48
49 #define fix_guile_1_4_scm_primitive_eval(form) scm_eval_3 (form, 1, SCM_EOL)
50 #define scm_primitive_eval(form) fix_guile_1_4_scm_primitive_eval (form)
51
52 #define scm_c_define_gsubr scm_make_gsubr
53 #define scm_c_eval_string(str) gh_eval_str ((char*)str)
54 #define scm_c_memq scm_sloppy_memq
55 #define scm_gc_protect_object scm_protect_object
56 #define scm_gc_unprotect_object scm_unprotect_object
57 #define scm_list_n scm_listify
58 #define SCM_STRING_CHARS SCM_CHARS
59 #define SCM_STRING_LENGTH SCM_LENGTH
60 #define SCM_SYMBOL_CHARS SCM_CHARS
61 #define SCM_SYMBOL_LENGTH SCM_LENGTH
62 #endif
63
64
65
66 #include "direction.hh"
67 #include "flower-proto.hh"
68
69 #ifndef SCM_PACK
70 #define SCM_PACK(x) ((SCM) x)
71
72 #endif
73 #ifndef SCM_UNPACK
74 #define SCM_UNPACK(x) ( x)
75 #endif
76
77 /*
78   conversion functions follow the GUILE naming convention, i.e.
79
80     A ly_B2A (B b);
81  */
82
83 SCM ly_last (SCM list);
84 SCM ly_str02scm (char const*c);
85 SCM ly_write2scm (SCM s);
86 SCM ly_deep_copy (SCM);
87 SCM ly_truncate_list (int k, SCM l );
88
89 #define CACHE_SYMBOLS
90 #ifdef CACHE_SYMBOLS
91
92 // #warning: CACHE_SYMBOLS
93
94 /*
95   Using this trick we cache the value of gh_symbol2scm ("fooo") where
96   "fooo" is a constant string. This is done at the cost of one static
97   variable per ly_symbol2scm() use, and one boolean evaluation for
98   every call.
99
100   The overall speedup of lily is about 5% on a run of wtk1-fugue2
101
102 */
103 #define ly_symbol2scm(x) ({ static SCM cached;  \
104  SCM value = cached;  /* We store this one locally, since G++ -O2 fucks up else */   \
105  if (__builtin_constant_p (x))\
106    value = cached =  scm_permanent_object (gh_symbol2scm((char*)x));\
107  else\
108   value = gh_symbol2scm ((char*)x); \
109   value; })
110 #else
111 inline SCM ly_symbol2scm(char const* x) { return gh_symbol2scm((char*)x); }
112 #endif 
113
114
115
116 String ly_scm2string (SCM s);
117 String ly_symbol2string (SCM);
118 SCM ly_offset2scm (Offset);
119 Offset ly_scm2offset (SCM);
120 SCM ly_assoc_chain (SCM key, SCM achain);
121 Interval ly_scm2interval (SCM);
122 SCM ly_interval2scm (Interval);
123
124 SCM ly_parse_scm (char const* s, int* n);
125 SCM ly_quote_scm (SCM s);
126 SCM ly_type (SCM);
127 bool type_check_assignment (SCM val, SCM sym,  SCM type_symbol) ;
128 SCM ly_number2string (SCM s);
129
130 SCM parse_symbol_list (char const *);
131
132 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
133 inline SCM ly_car (SCM x) { return SCM_CAR (x); } 
134 inline SCM ly_caar (SCM x) { return SCM_CAAR (x); }
135 inline SCM ly_cdar (SCM x) { return SCM_CDAR (x); }
136 inline SCM ly_cadr (SCM x) { return SCM_CADR (x); }
137 inline SCM ly_cddr (SCM x) { return SCM_CDDR (x); }
138 inline SCM ly_caddr (SCM x) { return SCM_CADDR (x); }
139 inline SCM ly_cdadr (SCM x) { return SCM_CDADR (x); }
140 inline SCM ly_caadr (SCM x) { return SCM_CAADR (x); }
141 inline bool ly_pair_p (SCM x) { return SCM_NFALSEP (scm_pair_p (x)); }
142 inline bool ly_symbol_p (SCM x) { return SCM_SYMBOLP (x); }
143 inline bool ly_number_p (SCM x) { return SCM_NUMBERP (x); }
144 inline bool ly_procedure_p (SCM x) { return SCM_NFALSEP (scm_procedure_p(x)); }
145
146 /*
147   display and print newline.
148  */
149 extern "C" { 
150 void ly_display_scm (SCM s);
151 }
152
153 #include "array.hh"
154
155 void read_lily_scm_file (String);
156 void init_lily_guile ();
157
158 bool isdir_b (SCM s);
159 bool isaxis_b (SCM s);
160 bool ly_number_pair_p (SCM);
161 bool ly_axis_p (SCM);
162
163 /*
164   these conversion functions also do a typecheck on the argument, and
165   return a default value if S has the wrong type.
166 */
167
168 Direction to_dir (SCM s);
169 bool to_boolean (SCM s);
170
171 void init_ly_protection ();
172 unsigned int ly_scm_hash (SCM s);
173
174 SCM index_cell (SCM cellp, Direction d);
175 SCM index_set_cell (SCM cellp, Direction d, SCM val);
176
177
178 /*
179   snarfing.
180  */
181 void add_scm_init_func (void (*) ());
182
183
184 typedef SCM (*Scheme_function_unknown) ();
185
186 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
187 typedef SCM (*Scheme_function_0) ();
188 typedef SCM (*Scheme_function_1) (SCM);
189 typedef SCM (*Scheme_function_2) (SCM,SCM);      
190 #else
191 typedef SCM (*Scheme_function_0) (...);
192 typedef SCM (*Scheme_function_1) (...);
193 typedef SCM (*Scheme_function_2) (...);
194 #endif
195
196 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
197         static SCM NAME ARGS; \
198         static SCM NAME ## _proc
199
200 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
201 SCM TYPE :: FUNC ## _proc;\
202 void                                                            \
203 TYPE ## _ ## FUNC ## _init_functions ()                                 \
204 {                                                               \
205   TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT  ## _0 (#TYPE "::" #FUNC, \
206  ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC));                                 \
207 }                                                               \
208                                                                 \
209 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions);       \
210
211
212 #define ADD_SCM_INIT_FUNC(name, func)\
213 class name ## _scm_initter {                    \
214 public:\
215   name ## _scm_initter ()                       \
216   {                                             \
217     add_scm_init_func (func);           \
218   }                                             \
219 } _ ## name ## _scm_initter;                    \
220 /* end define */
221
222 #endif // LILY_GUILE_HH