]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
Run grand-replace (issue 3765)
[lilypond.git] / lily / include / lily-guile.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2014 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef LILY_GUILE_HH
21 #define LILY_GUILE_HH
22
23 #if __MINGW32__
24 #include "mingw-compatibility.hh"
25 #endif
26
27 #include <libguile.h>
28 #include <string.h>
29
30 /*
31   Hack for various MacOS incarnations.
32  */
33 #ifndef GUILE_ELLIPSIS
34 #define GUILE_ELLIPSIS
35 #endif
36
37 #include "guile-compatibility.hh"
38 #include "interval.hh"
39 #include "lily-guile-macros.hh"
40 #include "ly-module.hh"
41 #include "std-vector.hh"
42
43 /** Conversion functions follow the GUILE naming convention, i.e.
44     A ly_B2A (B b);  */
45
46 SCM ly_last (SCM list);
47 string ly_scm_write_string (SCM s);
48 SCM ly_deep_copy (SCM);
49 SCM ly_truncate_list (int k, SCM lst);
50
51 extern SCM global_lily_module;
52
53 string gulp_file_to_string (const string &fn, bool must_exist, int size);
54
55 SCM ly_string2scm (string const &s);
56 string ly_scm2string (SCM s);
57 string ly_symbol2string (SCM);
58 string robust_symbol2string (SCM, const string&);
59 Rational ly_scm2rational (SCM);
60 SCM ly_rational2scm (Rational);
61 SCM ly_offset2scm (Offset);
62 Offset ly_scm2offset (SCM);
63 SCM ly_chain_assoc (SCM key, SCM achain);
64 SCM ly_chain_assoc_get (SCM key, SCM achain, SCM default_value, SCM strict_checking = SCM_BOOL_F);
65 SCM ly_assoc_cdr (SCM key, SCM alist);
66 SCM ly_assoc_get (SCM key, SCM alist, SCM default_value, SCM strict_checking = SCM_BOOL_F);
67 Interval ly_scm2interval (SCM);
68 Drul_array<Real> ly_scm2realdrul (SCM);
69 Slice int_list_to_slice (SCM l);
70 SCM ly_interval2scm (Drul_array<Real>);
71 char *ly_scm2str0 (SCM str);
72
73 Real robust_scm2double (SCM, double);
74 int robust_scm2int (SCM, int);
75 vsize robust_scm2vsize (SCM, vsize);
76 Direction robust_scm2dir (SCM, Direction);
77 Drul_array<Real> robust_scm2drul (SCM, Drul_array<Real>);
78 Drul_array<bool> robust_scm2booldrul (SCM, Drul_array<bool>);
79 Interval robust_scm2interval (SCM, Drul_array<Real>);
80 Offset robust_scm2offset (SCM, Offset);
81 string robust_scm2string (SCM, const string&);
82 Rational robust_scm2rational (SCM, Rational);
83 vector<Real> ly_scm2floatvector (SCM);
84 SCM ly_floatvector2scm (vector<Real> v);
85
86 SCM ly_quote_scm (SCM s);
87 bool type_check_assignment (SCM val, SCM sym, SCM type_symbol);
88 string print_scm_val (SCM val);
89 SCM ly_number2string (SCM s);
90
91 SCM parse_symbol_list (char const *);
92 SCM robust_list_ref (int i, SCM l);
93 SCM alist_to_hashq (SCM);
94
95 SCM ly_alist_vals (SCM alist);
96 SCM ly_hash2alist (SCM tab);
97 SCM ly_hash_table_keys (SCM tab);
98
99 SCM ly_assoc_prepend_x (SCM alist, SCM key, SCM val);
100
101 inline bool ly_is_list (SCM x) { return scm_is_true (scm_list_p (x)); }
102 inline bool ly_cheap_is_list (SCM x) { return scm_is_pair (x) || x == SCM_EOL; }
103 inline bool ly_is_procedure (SCM x) { return scm_is_true (scm_procedure_p (x)); }
104 inline bool ly_is_port (SCM x) { return scm_is_true (scm_port_p (x)); }
105
106 bool ly_is_rational (SCM);
107 /*
108   want to take the address of this function; scm_is_symbol() is a
109   macro.
110  */
111 inline bool ly_is_symbol (SCM x) { return scm_is_symbol (x); }
112
113 inline bool ly_is_equal (SCM x, SCM y)
114 {
115   return scm_is_true (scm_equal_p (x, y));
116 }
117
118 inline bool ly_scm2bool (SCM x) { return scm_is_true (x); }
119 inline char ly_scm2char (SCM x) { return (char)SCM_CHAR (x); }
120 inline SCM ly_bool2scm (bool x) { return scm_from_bool (x); }
121
122 inline SCM ly_append2 (SCM x1, SCM x2)
123 {
124   return scm_append (scm_listify (x1, x2, SCM_UNDEFINED));
125 }
126 inline SCM ly_append3 (SCM x1, SCM x2, SCM x3)
127 {
128   return scm_append (scm_listify (x1, x2, x3, SCM_UNDEFINED));
129 }
130 inline SCM ly_append4 (SCM x1, SCM x2, SCM x3, SCM x4)
131 {
132   return scm_append (scm_listify (x1, x2, x3, x4, SCM_UNDEFINED));
133 }
134
135 /*
136   display and print newline.
137 */
138 extern "C" {
139   void ly_display_scm (SCM s);
140 }
141
142 void read_lily_scm_file (string);
143 void ly_c_init_guile ();
144
145 bool is_direction (SCM s);
146 bool is_number_pair (SCM);
147 bool is_axis (SCM);
148
149 /*
150   these conversion functions also do a typecheck on the argument, and
151   return a default value if S has the wrong type.
152 */
153
154 Direction to_dir (SCM s);
155 bool to_boolean (SCM s);
156
157 void init_ly_protection ();
158 unsigned int ly_scm_hash (SCM s);
159
160 SCM index_get_cell (SCM cell, Direction d);
161 SCM index_set_cell (SCM cell, Direction d, SCM val);
162
163 SCM ly_snoc (SCM s, SCM list);
164 SCM ly_split_list (SCM s, SCM lst);
165 SCM ly_unique (SCM lst);
166 SCM ly_list_qsort_uniq_x (SCM lst);
167
168 SCM ly_output_formats ();
169
170 /*
171   snarfing.
172 */
173 void add_scm_init_func (void ( *) ());
174
175 extern "C" {
176   typedef SCM (*Scheme_function_unknown) (GUILE_ELLIPSIS);
177 }
178
179 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
180 typedef SCM (*Scheme_function_0) ();
181 typedef SCM (*Scheme_function_1) (SCM);
182 typedef SCM (*Scheme_function_2) (SCM, SCM);
183 typedef SCM (*Scheme_function_3) (SCM, SCM, SCM);
184 #else
185 typedef SCM (*Scheme_function_0) (GUILE_ELLIPSIS);
186 typedef SCM (*Scheme_function_1) (GUILE_ELLIPSIS);
187 typedef SCM (*Scheme_function_2) (GUILE_ELLIPSIS);
188 typedef SCM (*Scheme_function_3) (GUILE_ELLIPSIS);
189 #endif
190
191 /*
192   Inline these for performance reasons.
193  */
194 #define scm_cdr ly_cdr
195 #define scm_car ly_car
196
197 #ifndef scm_is_pair
198 #define scm_is_pair ly_is_pair
199 #endif
200
201 inline SCM ly_car (SCM x) { return SCM_CAR (x); }
202 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
203 inline bool ly_is_pair (SCM x) { return SCM_I_CONSP (x); }
204
205 #include "std-vector.hh"
206
207 template<class T>
208 SCM
209 ly_cxx_vector_to_list (vector<T> const &src)
210 {
211   SCM l = SCM_EOL;
212   for (vsize i = src.size (); i--;)
213     l = scm_cons (src[i]->self_scm (), l);
214
215   return l;
216 }
217
218 SCM ly_offsets2scm (vector<Offset> os);
219 vector<Offset> ly_scm2offsets (SCM s);
220
221 #endif /* LILY_GUILE_HH */