]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
release: 1.4.8
[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   TODO: the  GH interface is deprecated as of GUILE 1.6
15
16   Remove all gh_XXX functions.
17  */
18 #include <guile/gh.h>
19
20 #include "config.h"
21
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 #include "direction.hh"
54 #include "flower-proto.hh"
55
56 #ifndef SCM_PACK
57 #define SCM_PACK(x) ((SCM) x)
58
59 #endif
60 #ifndef SCM_UNPACK
61 #define SCM_UNPACK(x) ( x)
62 #endif
63
64
65
66
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_symbol2scm (char const *);
79 String ly_scm2string (SCM s);
80 String ly_symbol2string (SCM);
81 SCM ly_offset2scm (Offset);
82 Offset ly_scm2offset (SCM);
83 SCM ly_assoc_chain (SCM key, SCM achain);
84 Interval ly_scm2interval (SCM);
85 SCM ly_interval2scm (Interval);
86
87 SCM ly_parse_scm (char const* s, int* n);
88 SCM ly_quote_scm (SCM s);
89 SCM ly_type (SCM);
90 bool type_check_assignment (SCM val, SCM sym,  SCM type_symbol) ;
91 SCM ly_number2string (SCM s);
92
93 /*
94   display and print newline.
95  */
96 extern "C" { 
97 void ly_display_scm (SCM s);
98 }
99
100 #include "array.hh"
101
102 void read_lily_scm_file (String);
103 void init_lily_guile ();
104
105 bool isdir_b (SCM s);
106 bool isaxis_b (SCM s);
107 bool ly_number_pair_p (SCM);
108 bool ly_axis_p (SCM);
109
110 /*
111   these conversion functions also do a typecheck on the argument, and
112   return a default value if S has the wrong type.
113 */
114
115 Direction to_dir (SCM s);
116 bool to_boolean (SCM s);
117
118 void init_ly_protection ();
119 unsigned int ly_scm_hash (SCM s);
120
121 SCM index_cell (SCM cellp, Direction d);
122 SCM index_set_cell (SCM cellp, Direction d, SCM val);
123
124
125 /*
126   snarfing.
127  */
128 void add_scm_init_func (void (*) ());
129
130
131 typedef SCM (*Scheme_function_unknown) ();
132
133 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
134 typedef SCM (*Scheme_function_0) ();
135 typedef SCM (*Scheme_function_1) (SCM);
136 typedef SCM (*Scheme_function_2) (SCM,SCM);      
137 #else
138 typedef SCM (*Scheme_function_0) (...);
139 typedef SCM (*Scheme_function_1) (...);
140 typedef SCM (*Scheme_function_2) (...);
141 #endif
142
143 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
144         static SCM NAME ARGS; \
145         static SCM NAME ## _proc
146
147 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
148 SCM TYPE :: FUNC ## _proc;\
149 void                                                            \
150 TYPE ## _ ## FUNC ## _init_functions ()                                 \
151 {                                                               \
152   TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT  ## _0 (#TYPE "::" #FUNC, \
153  ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC));                                 \
154 }                                                               \
155                                                                 \
156 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions);       \
157
158
159 #define ADD_SCM_INIT_FUNC(name, func)\
160 class name ## _scm_initter {                    \
161 public:\
162   name ## _scm_initter ()                       \
163   {                                             \
164     add_scm_init_func (func);           \
165   }                                             \
166 } _ ## name ## _scm_initter;                    \
167 /* end define */
168
169 #endif // LILY_GUILE_HH