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