2005-01-07 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/include/lily-guile-macros.hh: new file.
+
+ * lily/pango-select-scheme.cc (LY_DEFINE): new file.
+
* lily/general-scheme.cc: new file.
* lily/font-select.cc (get_font_by_design_size): retrieve
#include "warn.hh"
#include "pango-font.hh"
-LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
- (SCM paper_smob, SCM chain),
-
- "Return a font metric satisfying the font-qualifiers "
- "in the alist chain @var{chain}.\n"
- "(An alist chain is a list of alists, "
- "containing grob properties).\n")
-{
- Output_def *paper = unsmob_output_def (paper_smob);
- SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1,
- __FUNCTION__, "paper definition");
-
- Font_metric *fm = select_font (paper, chain);
- return fm->self_scm ();
-}
-
-LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
- (SCM layout_smob, SCM name),
- "Return the layout variable @var{name}.")
-{
- Output_def *layout = unsmob_output_def (layout_smob);
- SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
- __FUNCTION__, "layout definition");
- return scm_make_real (layout->get_dimension (name));
-}
bool
wild_compare (SCM field_val, SCM val)
--- /dev/null
+/*
+ lily/grob-interface-scheme.cc -- implement
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#include "lily-guile.hh"
+
+Protected_scm all_ifaces;
+
+LY_DEFINE (ly_add_interface, "ly:add-interface", 3,0,0, (SCM a, SCM b, SCM c),
+ "Add an interface description.")
+{
+ SCM_ASSERT_TYPE (scm_is_symbol (a), a, SCM_ARG1, __FUNCTION__, "symbol");
+ SCM_ASSERT_TYPE (scm_is_string (b), b, SCM_ARG2, __FUNCTION__, "string");
+ SCM_ASSERT_TYPE (ly_c_list_p (c), c, SCM_ARG3, __FUNCTION__, "list of syms");
+ if (!ly_c_vector_p (all_ifaces))
+ all_ifaces = scm_make_vector (scm_int2num (40), SCM_EOL);
+
+ SCM entry = scm_list_n (a, b, c, SCM_UNDEFINED);
+
+ scm_hashq_set_x (all_ifaces, a, entry);
+
+ return SCM_UNSPECIFIED;
+}
+
+
+LY_DEFINE (ly_all_grob_interfaces, "ly:all-grob-interfaces",
+ 0,0,0, (),
+ "Get a hash table with all interface descriptions.")
+{
+ return all_ifaces;
+}
+
#include "grob.hh"
#include "warn.hh"
-Protected_scm all_ifaces;
-
void add_interface (const char * symbol,
const char * descr,
const char * vars)
}
-LY_DEFINE (ly_add_interface, "ly:add-interface", 3,0,0, (SCM a, SCM b, SCM c),
- "Add an interface description.")
-{
- SCM_ASSERT_TYPE (scm_is_symbol (a), a, SCM_ARG1, __FUNCTION__, "symbol");
- SCM_ASSERT_TYPE (scm_is_string (b), b, SCM_ARG2, __FUNCTION__, "string");
- SCM_ASSERT_TYPE (ly_c_list_p (c), c, SCM_ARG3, __FUNCTION__, "list of syms");
- if (!ly_c_vector_p (all_ifaces))
- all_ifaces = scm_make_vector (scm_int2num (40), SCM_EOL);
-
- SCM entry = scm_list_n (a, b, c, SCM_UNDEFINED);
-
- scm_hashq_set_x (all_ifaces, a, entry);
-
- return SCM_UNSPECIFIED;
-}
-
-
-LY_DEFINE (ly_all_grob_interfaces, "ly:all-grob-interfaces",
- 0,0,0, (),
- "Get a hash table with all interface descriptions.")
-{
- return all_ifaces;
-}
-
void
check_interfaces_for_property (Grob const *me, SCM sym)
}
SCM ifs = me->get_property ("interfaces");
+ SCM all_ifaces = ly_all_grob_interfaces ();
bool found = false;
for (; !found && scm_is_pair (ifs); ifs = scm_cdr (ifs))
{
#include <libguile.h> /* SCM */
-void add_interface (const char * symbol,
- const char * descr,
- const char * vars);
-SCM ly_add_interface (SCM, SCM, SCM);
#define ADD_INTERFACE(cl,a,b,c) \
bool cl::has_interface(Grob*me)\
ADD_SCM_INIT_FUNC(cl ## ifaces, cl ## _init_ifaces);\
+
+void add_interface (const char * symbol,
+ const char * descr,
+ const char * vars);
+
+SCM ly_add_interface (SCM, SCM, SCM);
+SCM ly_all_grob_interfaces();
+
#endif /* INTERFACE_HH */
--- /dev/null
+/*
+ lily-guile-macros.hh -- declare
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef LILY_GUILE_MACROS_HH
+#define LILY_GUILE_MACROS_HH
+
+#ifndef SMOB_FREE_RETURN_VAL
+#define SMOB_FREE_RETURN_VAL(CL) 0
+#endif
+
+#ifndef SCM_PACK
+#define SCM_PACK(x) ((SCM) x)
+#endif
+
+#ifndef SCM_UNPACK
+#define SCM_UNPACK(x) (x)
+#endif
+
+
+#if (__GNUC__ > 2)
+/* Unreliable with gcc-2.x
+ FIXME: should add check for x86 as well? */
+#define CACHE_SYMBOLS
+#endif
+
+#ifdef CACHE_SYMBOLS
+
+/* Using this trick we cache the value of scm_str2symbol ("fooo") where
+ "fooo" is a constant string. This is done at the cost of one static
+ variable per ly_symbol2scm() use, and one boolean evaluation for
+ every call.
+
+ The overall speedup of lily is about 5% on a run of wtk1-fugue2. */
+#define ly_symbol2scm(x) \
+({ \
+ static SCM cached; \
+ /* We store this one locally, since G++ -O2 fucks up else */ \
+ SCM value = cached; \
+ if ( __builtin_constant_p ((x))) \
+ { \
+ if (!cached) \
+ value = cached = scm_gc_protect_object (scm_str2symbol ((x))); \
+ } \
+ else \
+ value = scm_str2symbol ((char*) (x)); \
+ value; \
+})
+#else
+inline SCM ly_symbol2scm(char const* x) { return scm_str2symbol ((x)); }
+#endif
+
+
+/*
+ TODO: rename me to ly_c_lily_module_eval
+ */
+#define ly_lily_module_constant(x) \
+({ \
+ static SCM cached; \
+ /* We store this one locally, since G++ -O2 fucks up else */ \
+ SCM value = cached; \
+ if ( __builtin_constant_p ((x))) \
+ { \
+ if (!cached) \
+ value = cached = scm_gc_protect_object (scm_eval (scm_str2symbol (x), \
+ global_lily_module)); \
+ } \
+ else \
+ value = scm_eval (scm_str2symbol (x), global_lily_module); \
+ value; \
+})
+
+
+
+/*
+ Adds the NAME as a Scheme function, and a variable to store the SCM
+ version of the function in the static variable NAME_proc
+ */
+#define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \
+ static SCM NAME ARGS; \
+ static SCM NAME ## _proc
+
+/*
+ Make TYPE::FUNC available as a Scheme function.
+ */
+#define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
+SCM TYPE :: FUNC ## _proc; \
+void \
+TYPE ## _ ## FUNC ## _init_functions () \
+{ \
+ TYPE :: FUNC ## _proc = scm_c_define_gsubr (#TYPE "::" #FUNC, \
+ (ARGCOUNT), 0, 0, \
+ (Scheme_function_unknown)TYPE :: FUNC); \
+ scm_c_export (#TYPE "::" #FUNC, NULL); \
+} \
+ \
+ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, \
+ TYPE ## _ ## FUNC ## _init_functions);
+
+
+void
+ly_add_function_documentation (SCM proc, char const *fname,
+ char const *varlist,
+ char const *doc);
+
+#define ADD_SCM_INIT_FUNC(name, func) \
+class name ## _scm_initter \
+{ \
+public: \
+ name ## _scm_initter () \
+ { \
+ add_scm_init_func (func); \
+ } \
+} _ ## name ## _scm_initter; \
+/* end define */
+
+#define LY_DEFINE_WITHOUT_DECL(INITPREFIX, FNAME, PRIMNAME, REQ, OPT, VAR, \
+ ARGLIST, DOCSTRING) \
+SCM FNAME ## _proc; \
+void \
+INITPREFIX ## init () \
+{ \
+ FNAME ## _proc = scm_c_define_gsubr (PRIMNAME,REQ, OPT, VAR, \
+ (Scheme_function_unknown) FNAME); \
+ ly_add_function_documentation (FNAME ## _proc, PRIMNAME, #ARGLIST, \
+ DOCSTRING); \
+ scm_c_export (PRIMNAME, NULL); \
+} \
+ADD_SCM_INIT_FUNC (INITPREFIX ## init_unique_prefix, INITPREFIX ## init); \
+SCM \
+FNAME ARGLIST
+
+
+#define LY_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
+SCM FNAME ARGLIST; \
+LY_DEFINE_WITHOUT_DECL (FNAME, FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, \
+ DOCSTRING)
+
+#define LY_DEFINE_MEMBER_FUNCTION(CLASS, FNAME, PRIMNAME, REQ, OPT, VAR, \
+ ARGLIST, DOCSTRING) \
+SCM FNAME ARGLIST; \
+LY_DEFINE_WITHOUT_DECL (CLASS ## FNAME, CLASS::FNAME, PRIMNAME, REQ, OPT, \
+ VAR, ARGLIST, DOCSTRING)
+
+#define get_property(x) internal_get_property (ly_symbol2scm (x))
+#define set_property(x, y) internal_set_property (ly_symbol2scm (x), y)
+
+#endif /* LILY_GUILE_MACROS_HH */
#include "interval.hh"
#include "guile-compatibility.hh"
+#include "lily-guile-macros.hh"
#include "ly-module.hh"
-#ifndef SMOB_FREE_RETURN_VAL
-#define SMOB_FREE_RETURN_VAL(CL) 0
-#endif
-
-#ifndef SCM_PACK
-#define SCM_PACK(x) ((SCM) x)
-#endif
-
-#ifndef SCM_UNPACK
-#define SCM_UNPACK(x) (x)
-#endif
/** Conversion functions follow the GUILE naming convention, i.e.
A ly_B2A (B b); */
SCM ly_to_string (SCM scm);
SCM ly_to_symbol (SCM scm);
-#if (__GNUC__ > 2)
-/* Unreliable with gcc-2.x
- FIXME: should add check for x86 as well? */
-#define CACHE_SYMBOLS
-#endif
-
-#ifdef CACHE_SYMBOLS
-
-/* Using this trick we cache the value of scm_str2symbol ("fooo") where
- "fooo" is a constant string. This is done at the cost of one static
- variable per ly_symbol2scm() use, and one boolean evaluation for
- every call.
-
- The overall speedup of lily is about 5% on a run of wtk1-fugue2. */
-#define ly_symbol2scm(x) \
-({ \
- static SCM cached; \
- /* We store this one locally, since G++ -O2 fucks up else */ \
- SCM value = cached; \
- if ( __builtin_constant_p ((x))) \
- { \
- if (!cached) \
- value = cached = scm_gc_protect_object (scm_str2symbol ((x))); \
- } \
- else \
- value = scm_str2symbol ((char*) (x)); \
- value; \
-})
-#else
-inline SCM ly_symbol2scm(char const* x) { return scm_str2symbol ((x)); }
-#endif
-
extern SCM global_lily_module;
-/*
- TODO: rename me to ly_c_lily_module_eval
- */
-#define ly_lily_module_constant(x) \
-({ \
- static SCM cached; \
- /* We store this one locally, since G++ -O2 fucks up else */ \
- SCM value = cached; \
- if ( __builtin_constant_p ((x))) \
- { \
- if (!cached) \
- value = cached = scm_gc_protect_object (scm_eval (scm_str2symbol (x), \
- global_lily_module)); \
- } \
- else \
- value = scm_eval (scm_str2symbol (x), global_lily_module); \
- value; \
-})
-
String gulp_file_to_string (String fn, bool must_exist);
String ly_scm2string (SCM s);
typedef SCM (*Scheme_function_2) (...);
typedef SCM (*Scheme_function_3) (...);
#endif
-
-
-/*
- Adds the NAME as a Scheme function, and a variable to store the SCM
- version of the function in the static variable NAME_proc
- */
-#define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \
- static SCM NAME ARGS; \
- static SCM NAME ## _proc
-
-/*
- Make TYPE::FUNC available as a Scheme function.
- */
-#define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT) \
-SCM TYPE :: FUNC ## _proc; \
-void \
-TYPE ## _ ## FUNC ## _init_functions () \
-{ \
- TYPE :: FUNC ## _proc = scm_c_define_gsubr (#TYPE "::" #FUNC, \
- (ARGCOUNT), 0, 0, \
- (Scheme_function_unknown)TYPE :: FUNC); \
- scm_c_export (#TYPE "::" #FUNC, NULL); \
-} \
- \
-ADD_SCM_INIT_FUNC (TYPE ## _ ## FUNC ## _callback, \
- TYPE ## _ ## FUNC ## _init_functions);
-
-
-void
-ly_add_function_documentation (SCM proc, char const *fname,
- char const *varlist,
- char const *doc);
-
-#define ADD_SCM_INIT_FUNC(name, func) \
-class name ## _scm_initter \
-{ \
-public: \
- name ## _scm_initter () \
- { \
- add_scm_init_func (func); \
- } \
-} _ ## name ## _scm_initter; \
-/* end define */
-
-#define LY_DEFINE_WITHOUT_DECL(INITPREFIX, FNAME, PRIMNAME, REQ, OPT, VAR, \
- ARGLIST, DOCSTRING) \
-SCM FNAME ## _proc; \
-void \
-INITPREFIX ## init () \
-{ \
- FNAME ## _proc = scm_c_define_gsubr (PRIMNAME,REQ, OPT, VAR, \
- (Scheme_function_unknown) FNAME); \
- ly_add_function_documentation (FNAME ## _proc, PRIMNAME, #ARGLIST, \
- DOCSTRING); \
- scm_c_export (PRIMNAME, NULL); \
-} \
-ADD_SCM_INIT_FUNC (INITPREFIX ## init_unique_prefix, INITPREFIX ## init); \
-SCM \
-FNAME ARGLIST
-
-
-#define LY_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
-SCM FNAME ARGLIST; \
-LY_DEFINE_WITHOUT_DECL (FNAME, FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, \
- DOCSTRING)
-
-#define LY_DEFINE_MEMBER_FUNCTION(CLASS, FNAME, PRIMNAME, REQ, OPT, VAR, \
- ARGLIST, DOCSTRING) \
-SCM FNAME ARGLIST; \
-LY_DEFINE_WITHOUT_DECL (CLASS ## FNAME, CLASS::FNAME, PRIMNAME, REQ, OPT, \
- VAR, ARGLIST, DOCSTRING)
-
-#define get_property(x) internal_get_property (ly_symbol2scm (x))
-#define set_property(x, y) internal_set_property (ly_symbol2scm (x), y)
-
#endif /* LILY_GUILE_HH */
*/
+#include "font-metric.hh"
#include "output-def.hh"
#include "ly-module.hh"
#include "context-def.hh"
Output_def *bp = new Output_def ;
return scm_gc_unprotect_object (bp->self_scm ());
}
+
+LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
+ (SCM paper_smob, SCM chain),
+
+ "Return a font metric satisfying the font-qualifiers "
+ "in the alist chain @var{chain}.\n"
+ "(An alist chain is a list of alists, "
+ "containing grob properties).\n")
+{
+ Output_def *paper = unsmob_output_def (paper_smob);
+ SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1,
+ __FUNCTION__, "paper definition");
+
+ Font_metric *fm = select_font (paper, chain);
+ return fm->self_scm ();
+}
+
+LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
+ (SCM layout_smob, SCM name),
+ "Return the layout variable @var{name}.")
+{
+ Output_def *layout = unsmob_output_def (layout_smob);
+ SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
+ __FUNCTION__, "layout definition");
+ return scm_make_real (layout->get_dimension (name));
+}