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