]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
* lily/include/lily-guile-macros.hh: new file.
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #ifndef LILY_GUILE_HH
10 #define LILY_GUILE_HH
11
12 #include <libguile.h>
13
14 #include "interval.hh"
15 #include "guile-compatibility.hh"
16 #include "lily-guile-macros.hh"
17 #include "ly-module.hh"
18
19
20 /** Conversion functions follow the GUILE naming convention, i.e.
21     A ly_B2A (B b);  */
22
23 SCM ly_last (SCM list);
24 SCM ly_write2scm (SCM s);
25 SCM ly_deep_copy (SCM);
26 SCM ly_truncate_list (int k, SCM lst);
27
28 SCM ly_to_string (SCM scm);
29 SCM ly_to_symbol (SCM scm);
30
31 extern SCM global_lily_module;
32
33 String gulp_file_to_string (String fn, bool must_exist);
34
35 String ly_scm2string (SCM s);
36 String ly_symbol2string (SCM);
37 SCM ly_offset2scm (Offset);
38 Offset ly_scm2offset (SCM);
39 SCM ly_chain_assoc (SCM key, SCM achain);
40 SCM ly_chain_assoc_get (SCM key, SCM achain, SCM dfault);
41 SCM ly_assoc_cdr (SCM key, SCM alist);
42 SCM ly_assoc_get (SCM key, SCM alist, SCM def);
43 Interval ly_scm2interval (SCM);
44 Drul_array<Real> ly_scm2realdrul (SCM);
45 Slice int_list_to_slice (SCM l);
46 SCM ly_interval2scm (Drul_array<Real>);
47 char *ly_scm2newstr (SCM str, size_t *lenp);
48
49 Real robust_scm2double (SCM, double);
50 int robust_scm2int (SCM, int);
51 Drul_array<Real> robust_scm2drul (SCM, Drul_array<Real>);
52 Interval robust_scm2interval (SCM, Drul_array<Real>);
53 Offset robust_scm2offset (SCM, Offset);
54
55 SCM ly_quote_scm (SCM s);
56 bool type_check_assignment (SCM val, SCM sym,  SCM type_symbol) ;
57 String print_scm_val (SCM val);
58 SCM ly_number2string (SCM s);
59
60 SCM parse_symbol_list (char const *);
61 SCM robust_list_ref(int i, SCM l);
62 SCM alist_to_hashq (SCM);
63
64
65 /* inserts at front, removing dublicates */
66 inline SCM ly_assoc_front_x(SCM alist, SCM key, SCM val)
67 {
68   return scm_acons(key, val, scm_assoc_remove_x (alist, key));
69 }
70 inline bool ly_c_char_p (SCM x) { return SCM_CHARP (x); }
71 inline bool ly_c_vector_p (SCM x) { return SCM_VECTORP (x); }
72 inline bool ly_c_list_p (SCM x) { return SCM_NFALSEP (scm_list_p (x)); }
73 inline bool ly_c_procedure_p (SCM x) { return SCM_NFALSEP (scm_procedure_p (x)); }
74 inline bool ly_c_equal_p (SCM x, SCM y) {
75   return SCM_NFALSEP (scm_equal_p (x, y));
76 }
77
78
79 inline bool ly_scm2bool (SCM x) { return SCM_NFALSEP (x); }
80 inline char ly_scm2char (SCM x) { return SCM_CHAR(x); }
81 inline unsigned long ly_length (SCM x) {
82   return scm_num2ulong (scm_length (x), 0, "ly_length");
83 }
84 inline unsigned long ly_vector_length (SCM x) { return SCM_VECTOR_LENGTH (x); }
85
86 inline SCM ly_bool2scm (bool x) { return SCM_BOOL (x); }
87
88 inline SCM ly_append2 (SCM x1, SCM x2) {
89   return scm_append (scm_listify (x1, x2, SCM_UNDEFINED));
90 }
91 inline SCM ly_append3 (SCM x1, SCM x2, SCM x3) {
92   return scm_append (scm_listify (x1, x2, x3, SCM_UNDEFINED));
93 }
94 inline SCM ly_append4 (SCM x1, SCM x2, SCM x3, SCM x4) {
95   return scm_append (scm_listify (x1, x2, x3, x4, SCM_UNDEFINED));
96 }
97
98 /*
99   display and print newline.
100  */
101 extern "C" {
102 void ly_display_scm (SCM s);
103 }
104
105 void read_lily_scm_file (String);
106 void ly_c_init_guile ();
107
108 bool is_direction (SCM s);
109 bool is_number_pair (SCM);
110 bool is_axis (SCM);
111
112 /*
113   these conversion functions also do a typecheck on the argument, and
114   return a default value if S has the wrong type.
115 */
116
117 Direction to_dir (SCM s);
118 bool to_boolean (SCM s);
119
120 void init_ly_protection ();
121 unsigned int ly_scm_hash (SCM s);
122
123 SCM index_get_cell (SCM cell, Direction d);
124 SCM index_set_cell (SCM cell, Direction d, SCM val);
125
126 SCM ly_snoc (SCM s, SCM list);
127 SCM ly_split_list (SCM s, SCM lst);
128 SCM ly_unique (SCM lst);
129 SCM ly_list_qsort_uniq_x (SCM lst);
130
131 SCM ly_output_formats();
132 SCM ly_kpathsea_find_file (SCM);
133
134 /*
135   snarfing.
136  */
137 void add_scm_init_func (void (*) ());
138
139 extern "C" {
140 typedef SCM (*Scheme_function_unknown) ();
141 }
142
143 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
144 typedef SCM (*Scheme_function_0) ();
145 typedef SCM (*Scheme_function_1) (SCM);
146 typedef SCM (*Scheme_function_2) (SCM,SCM);     
147 typedef SCM (*Scheme_function_3) (SCM,SCM, SCM);        
148 #else
149 typedef SCM (*Scheme_function_0) (...);
150 typedef SCM (*Scheme_function_1) (...);
151 typedef SCM (*Scheme_function_2) (...);
152 typedef SCM (*Scheme_function_3) (...);
153 #endif
154 #endif /* LILY_GUILE_HH */