]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
patch::: 1.5.12.jcn1
[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 #endif
52
53
54
55 #include "direction.hh"
56 #include "flower-proto.hh"
57
58 #ifndef SCM_PACK
59 #define SCM_PACK(x) ((SCM) x)
60
61 #endif
62 #ifndef SCM_UNPACK
63 #define SCM_UNPACK(x) ( x)
64 #endif
65
66 /*
67   conversion functions follow the GUILE naming convention, i.e.
68
69     A ly_B2A (B b);
70  */
71
72 SCM ly_last (SCM list);
73 SCM ly_str02scm (char const*c);
74 SCM ly_write2scm (SCM s);
75 SCM ly_deep_copy (SCM);
76 SCM ly_symbol2scm (char const *);
77 String ly_scm2string (SCM s);
78 String ly_symbol2string (SCM);
79 SCM ly_offset2scm (Offset);
80 Offset ly_scm2offset (SCM);
81 SCM ly_assoc_chain (SCM key, SCM achain);
82 Interval ly_scm2interval (SCM);
83 SCM ly_interval2scm (Interval);
84
85 SCM ly_parse_scm (char const* s, int* n);
86 SCM ly_quote_scm (SCM s);
87 SCM ly_type (SCM);
88 bool type_check_assignment (SCM val, SCM sym,  SCM type_symbol) ;
89 SCM ly_number2string (SCM s);
90
91 inline SCM
92 ly_cdr (SCM x)
93 {
94   return SCM_CDR (x);
95 }
96 inline SCM
97 ly_car (SCM x)
98 {
99   return SCM_CAR (x);
100
101 inline SCM
102 ly_caar (SCM x)
103 {
104   return SCM_CAAR (x);
105 }
106 inline SCM
107 ly_cdar (SCM x)
108 {
109   return SCM_CDAR (x);
110 }
111 inline SCM
112 ly_cadr (SCM x)
113 {
114   return SCM_CADR (x);
115 }
116 inline SCM
117 ly_cddr (SCM x)
118 {
119   return SCM_CDDR (x);
120 }
121 inline SCM
122 ly_pair_p (SCM x)
123 {
124   return scm_pair_p (x);
125 }
126 inline bool
127 ly_symbol_p (SCM x)
128 {
129   return SCM_SYMBOLP (x);
130 }
131 inline bool
132 ly_number_p (SCM x)
133 {
134   return SCM_NUMBERP (x);
135 }
136 inline bool
137 ly_procedure_p (SCM x)
138 {
139   return SCM_NFALSEP (scm_procedure_p(x));
140 }
141
142 /*
143   display and print newline.
144  */
145 extern "C" { 
146 void ly_display_scm (SCM s);
147 }
148
149 #include "array.hh"
150
151 void read_lily_scm_file (String);
152 void init_lily_guile ();
153
154 bool isdir_b (SCM s);
155 bool isaxis_b (SCM s);
156 bool ly_number_pair_p (SCM);
157 bool ly_axis_p (SCM);
158
159 /*
160   these conversion functions also do a typecheck on the argument, and
161   return a default value if S has the wrong type.
162 */
163
164 Direction to_dir (SCM s);
165 bool to_boolean (SCM s);
166
167 void init_ly_protection ();
168 unsigned int ly_scm_hash (SCM s);
169
170 SCM index_cell (SCM cellp, Direction d);
171 SCM index_set_cell (SCM cellp, Direction d, SCM val);
172
173
174 /*
175   snarfing.
176  */
177 void add_scm_init_func (void (*) ());
178
179
180 typedef SCM (*Scheme_function_unknown) ();
181
182 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
183 typedef SCM (*Scheme_function_0) ();
184 typedef SCM (*Scheme_function_1) (SCM);
185 typedef SCM (*Scheme_function_2) (SCM,SCM);      
186 #else
187 typedef SCM (*Scheme_function_0) (...);
188 typedef SCM (*Scheme_function_1) (...);
189 typedef SCM (*Scheme_function_2) (...);
190 #endif
191
192 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
193         static SCM NAME ARGS; \
194         static SCM NAME ## _proc
195
196 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
197 SCM TYPE :: FUNC ## _proc;\
198 void                                                            \
199 TYPE ## _ ## FUNC ## _init_functions ()                                 \
200 {                                                               \
201   TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT  ## _0 (#TYPE "::" #FUNC, \
202  ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC));                                 \
203 }                                                               \
204                                                                 \
205 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions);       \
206
207
208 #define ADD_SCM_INIT_FUNC(name, func)\
209 class name ## _scm_initter {                    \
210 public:\
211   name ## _scm_initter ()                       \
212   {                                             \
213     add_scm_init_func (func);           \
214   }                                             \
215 } _ ## name ## _scm_initter;                    \
216 /* end define */
217
218 #endif // LILY_GUILE_HH