From 6c00542bf11cd4759b2e39537aeb3d9a533a3519 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 7 Jan 2005 13:22:39 +0000 Subject: [PATCH] * lily/include/lily-guile-macros.hh: new file. * lily/font-select.cc (get_font_by_design_size): retrieve PangoFont for (designsize . "pango-descr") entries. * lily/output-def-scheme.cc: new file. --- ChangeLog | 4 + lily/font-select.cc | 25 ----- lily/grob-interface-scheme.cc | 37 ++++++++ lily/grob-interface.cc | 27 +----- lily/include/grob-interface.hh | 12 ++- lily/include/lily-guile-macros.hh | 153 ++++++++++++++++++++++++++++++ lily/include/lily-guile.hh | 138 +-------------------------- lily/output-def-scheme.cc | 27 ++++++ 8 files changed, 231 insertions(+), 192 deletions(-) create mode 100644 lily/grob-interface-scheme.cc create mode 100644 lily/include/lily-guile-macros.hh diff --git a/ChangeLog b/ChangeLog index fe1fd35e8e..b15e4d8321 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2005-01-07 Han-Wen Nienhuys + * 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 diff --git a/lily/font-select.cc b/lily/font-select.cc index 68cdc5e497..5f8ca95b2f 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -15,31 +15,6 @@ #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) diff --git a/lily/grob-interface-scheme.cc b/lily/grob-interface-scheme.cc new file mode 100644 index 0000000000..466c4bbcbb --- /dev/null +++ b/lily/grob-interface-scheme.cc @@ -0,0 +1,37 @@ +/* + lily/grob-interface-scheme.cc -- implement + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#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; +} + diff --git a/lily/grob-interface.cc b/lily/grob-interface.cc index 8bcf12bddd..f1d686f9b2 100644 --- a/lily/grob-interface.cc +++ b/lily/grob-interface.cc @@ -12,8 +12,6 @@ #include "grob.hh" #include "warn.hh" -Protected_scm all_ifaces; - void add_interface (const char * symbol, const char * descr, const char * vars) @@ -26,30 +24,6 @@ void add_interface (const char * symbol, } -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) @@ -64,6 +38,7 @@ 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)) { diff --git a/lily/include/grob-interface.hh b/lily/include/grob-interface.hh index a3194a9a13..d764ae4e6e 100644 --- a/lily/include/grob-interface.hh +++ b/lily/include/grob-interface.hh @@ -12,11 +12,7 @@ #include /* 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)\ @@ -29,5 +25,13 @@ void cl ## _init_ifaces() {\ 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 */ diff --git a/lily/include/lily-guile-macros.hh b/lily/include/lily-guile-macros.hh new file mode 100644 index 0000000000..526d1ec226 --- /dev/null +++ b/lily/include/lily-guile-macros.hh @@ -0,0 +1,153 @@ +/* + lily-guile-macros.hh -- declare + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#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 */ diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 13d50328fd..f6cb2c1482 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -13,19 +13,9 @@ #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); */ @@ -38,59 +28,8 @@ SCM ly_truncate_list (int k, SCM lst); 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); @@ -212,79 +151,4 @@ typedef SCM (*Scheme_function_1) (...); 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 */ diff --git a/lily/output-def-scheme.cc b/lily/output-def-scheme.cc index 5465ef4075..88d6f28c49 100644 --- a/lily/output-def-scheme.cc +++ b/lily/output-def-scheme.cc @@ -7,6 +7,7 @@ */ +#include "font-metric.hh" #include "output-def.hh" #include "ly-module.hh" #include "context-def.hh" @@ -94,3 +95,29 @@ LY_DEFINE (ly_make_output_def, "ly:make-output-def", 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)); +} -- 2.39.5