]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/lily-guile-macros.hh
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / include / lily-guile-macros.hh
index 221bcef76c4b31cde794e950096b604eddf28988..ef0db4747900b271fe9c362d06eeefe9bdbbf020 100644 (file)
@@ -3,8 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
+  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #ifndef LILY_GUILE_MACROS_HH
@@ -22,7 +21,6 @@
 #define SCM_UNPACK(x) (x)
 #endif
 
-
 #if (__GNUC__ > 2)
 /* Unreliable with gcc-2.x
    FIXME: should add check for x86 as well?  */
 #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; \
-})
+   "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)); }
+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; \
-})
 
+  we don't have to protect the result; it's already part of the
+  exports list of the module.
+*/
 
+#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_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
-
+*/
+#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);
-
+*/
+string mangle_cxx_identifier (string);
+#define MAKE_SCHEME_CALLBACK(TYPE, FUNC, ARGCOUNT)                     \
+  SCM TYPE ::FUNC ## _proc;                                            \
+  void                                                                 \
+  TYPE ## _ ## FUNC ## _init_functions ()                              \
+  {                                                                    \
+    string id = mangle_cxx_identifier (string (#TYPE) + "::" + string (#FUNC)); \
+    TYPE ::FUNC ## _proc = scm_c_define_gsubr (id.c_str(),                     \
+                                              (ARGCOUNT), 0, 0,        \
+                                              (Scheme_function_unknown) TYPE::FUNC); \
+    scm_c_export (id.c_str (), 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; \
+#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)
+                              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)
+                                 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 get_object(x) internal_get_object (ly_symbol2scm (x))
 #define set_property(x, y) internal_set_property (ly_symbol2scm (x), y)
+#define set_object(x, y) internal_set_object (ly_symbol2scm (x), y)
 
 #endif /* LILY_GUILE_MACROS_HH */