]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
patch::: 1.5.2.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 <guile/gh.h>
13 #include <libguile.h>
14 #include "config.h"
15
16 /* Guile 1.3.4 compatibility */
17 #if GUILE_MINOR_VERSION < 4
18
19 #define scm_bits_t SCM
20
21 #define fix_guile_1_3_4_scm_puts(scm_data, port) scm_puts ((char*)scm_data, port)
22 #define scm_puts(scm_data, port) fix_guile_1_3_4_scm_puts (scm_data, port)
23 #endif
24
25 /* Guile 1.4.x compatibility */
26 #if GUILE_MINOR_VERSION < 5
27
28 #define scm_t_bits scm_bits_t
29
30 #define fix_guile_1_4_gh_scm2newstr(str, lenp) gh_scm2newstr (str, (int*)lenp)
31 #define gh_scm2newstr(str, lenp) fix_guile_1_4_gh_scm2newstr (str, lenp)
32
33 #define fix_guile_1_4_scm_primitive_eval(form) scm_eval_3 (form, 1, SCM_EOL)
34 #define scm_primitive_eval(form) fix_guile_1_4_scm_primitive_eval (form)
35
36 #define scm_c_define_gsubr scm_make_gsubr
37 #define scm_c_memq scm_sloppy_memq
38 #define scm_gc_protect_object scm_protect_object
39 #define scm_gc_unprotect_object scm_unprotect_object
40 #define scm_list_n scm_listify
41 #define SCM_STRING_CHARS SCM_CHARS
42 #define SCM_STRING_LENGTH SCM_LENGTH
43 #endif
44
45
46
47 #include "direction.hh"
48 #include "flower-proto.hh"
49
50 #ifndef SCM_PACK
51 #define SCM_PACK(x) ((SCM) x)
52
53 #endif
54 #ifndef SCM_UNPACK
55 #define SCM_UNPACK(x) ( x)
56 #endif
57
58 /*
59   conversion functions follow the GUILE naming convention, i.e.
60
61     A ly_B2A (B b);
62  */
63
64 SCM ly_last (SCM list);
65 SCM ly_str02scm (char const*c);
66 SCM ly_write2scm (SCM s);
67 SCM ly_deep_copy (SCM);
68 SCM ly_symbol2scm (char const *);
69 String ly_scm2string (SCM s);
70 String ly_symbol2string (SCM);
71 SCM ly_offset2scm (Offset);
72 Offset ly_scm2offset (SCM);
73 SCM ly_assoc_chain (SCM key, SCM achain);
74 Interval ly_scm2interval (SCM);
75 SCM ly_interval2scm (Interval);
76
77 SCM ly_parse_scm (char const* s, int* n);
78 SCM ly_quote_scm (SCM s);
79 SCM ly_type (SCM);
80 bool type_check_assignment (SCM val, SCM sym,  SCM type_symbol) ;
81 SCM ly_number2string (SCM s);
82
83 /*
84   display and print newline.
85  */
86 extern "C" { 
87 void ly_display_scm (SCM s);
88 }
89
90 #include "array.hh"
91
92 void read_lily_scm_file (String);
93 void init_lily_guile ();
94
95 bool isdir_b (SCM s);
96 bool isaxis_b (SCM s);
97 bool ly_number_pair_p (SCM);
98 bool ly_axis_p (SCM);
99
100 /*
101   these conversion functions also do a typecheck on the argument, and
102   return a default value if S has the wrong type.
103 */
104
105 Direction to_dir (SCM s);
106 bool to_boolean (SCM s);
107
108 void init_ly_protection ();
109 unsigned int ly_scm_hash (SCM s);
110
111 SCM index_cell (SCM cellp, Direction d);
112 SCM index_set_cell (SCM cellp, Direction d, SCM val);
113
114
115 /*
116   snarfing.
117  */
118 void add_scm_init_func (void (*) ());
119
120
121 typedef SCM (*Scheme_function_unknown) ();
122
123 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
124 typedef SCM (*Scheme_function_0) ();
125 typedef SCM (*Scheme_function_1) (SCM);
126 typedef SCM (*Scheme_function_2) (SCM,SCM);      
127 #else
128 typedef SCM (*Scheme_function_0) (...);
129 typedef SCM (*Scheme_function_1) (...);
130 typedef SCM (*Scheme_function_2) (...);
131 #endif
132
133 #define DECLARE_SCHEME_CALLBACK(NAME,ARGS) \
134         static SCM NAME ARGS; \
135         static SCM NAME ## _proc
136
137 #define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
138 SCM TYPE :: FUNC ## _proc;\
139 void                                                            \
140 TYPE ## _ ## FUNC ## _init_functions ()                                 \
141 {                                                               \
142   TYPE :: FUNC ## _proc = gh_new_procedure ## ARGCOUNT  ## _0 (#TYPE "::" #FUNC, \
143  ((Scheme_function_ ## ARGCOUNT)TYPE :: FUNC));                                 \
144 }                                                               \
145                                                                 \
146 ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, TYPE ## _ ## FUNC ## _init_functions);       \
147
148
149 #define ADD_SCM_INIT_FUNC(name, func)\
150 class name ## _scm_initter {                    \
151 public:\
152   name ## _scm_initter ()                       \
153   {                                             \
154     add_scm_init_func (func);           \
155   }                                             \
156 } _ ## name ## _scm_initter;                    \
157 /* end define */
158
159 #endif // LILY_GUILE_HH